我想要一個像圖片上那樣的圓形按鈕
。
并改變按鈕背景的顏色 沒有類(我不知道如何使用類,如果你教我,我也可以使用它),用python tkinter。 我試過了
button = CustomButton(window, 100, 25, 'red' /span>)
并且我得到一個錯誤 NameError: name 'CustomButton' is not defined
這是我的代碼
import tkinter as tk
from tkinter import *
from tkinter import font
#declarando a variavel da janela[/span]。
window = tk.Tk()
#mudando o titulo da janela#/span
window.title('sorteio')
#colocando o favicon na a
window.iconbitmap("./img/pinguim.ico")
#pegando a resolu??o do monitor and colocando a variavel
widthValue = window.winfo_screenwidth()
heightValue = window.winfo_screenheight()
window.geometry("%dx%d 0 0" % (widthValue,heightValue)
#↑
#passando o valor de "%dx%d"
#deixando maximizada ao iniciar
window.state('zoomed')
#定義影像
bg = PhotoImage(file="./img/background.png")
#創建畫布
canvas1 = Canvas(window, width=widthValue, height=heightValue, bd=0 , highlightthickness=0)#highlightthickness= 0 tira a borda branca。
canvas1.pack(fill="both", expand=True)
#colocando a imagem no canvas。
canvas1.create_image(0,0, image=bg , anchor="nw")
#criando texto[/span]。
canvas1. create_text(900,100, text="Sorteio" , font=("Roboto", 25), fill="白色", anchor="中心")
canvas1. create_text(680,300, text=" Sortear entre: ", font=("Roboto", 12), fill="白色" )
inputMin = Entry(canvas1)
canvas1.create_window(800, 300, window=inputMin, height=25, width=120)
inputMin.insert(0, "minimo")
inputMin.config(fg="#808080", font="Roboto")
canvas1. create_text(885,300, text="e。 ", font=("Roboto",12), fill="白色")
inputMax = Entry(canvas1)
inputMax.insert(0, "maximo")
inputMax.config(fg="#808080", font="Roboto")
canvas1.create_window(955, 300, window=inputMax, height=25, width=120)
#fun??o[/span]。
def sortear() 。
print("ooi")
#primeiro cria o texto depois escolhe a posi??o dele。
#textoSorteio = Label(window, text="Sorteio",font=("Roboto", 25), fg="white")#passando a janela pro textto。
#textoSorteio.pack(pady=50)
button = CustomButton(window, 100, 25, 'red' /span>)
btnSorte = canvas1.create_oval()
btnSortear = Button(window, text="Sortear", width=15, height=1, pady=5, command=sortear)
btnSortear.place(x=1100, y=500)
window.mainloop()
uj5u.com熱心網友回復:
問題是,你使用了一個由別人創建的類,并且沒有在你的代碼中包含它。CustomButton類需要被包含在你的檔案的頂部。
我真的希望你能閱讀一下類的內容。面向物件的編程是python的基礎,也是如何撰寫更復雜的代碼的基礎。
uj5u.com熱心網友回復:
你需要在你的檔案中包含該類,或者在一個單獨的檔案中,然后匯入它。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/315136.html
標籤:
下一篇:如何修復螢屏末端的按鈕

