[英]tkinter button color autochanging
root = Tk()
root.title('Tic-Tac-Toe by Ahmed')
root.geometry('500x500')
logo = PhotoImage(file = 'download.gif')
style = ttk.Style()
style.theme_use('clam')
print(style.theme_names())
style.configure('TButton', background = 'black', foreground = 'white', font = ('Arial', 30, 'bold'))
ttk.Label(root, text = 'Welcome to Tic-Tac-Toe by Ahmed', background = 'black', foreground = 'red', font = ('Arial',20,'italic'), anchor = 'center')\
.grid(row = 0, column = 1, sticky = 'ew')
playbtn = ttk.Button(root, text = 'Play')
playbtn.grid(row = 1, column = 1, sticky = 'snew')
root.call('wm','iconphoto',root,logo)
root.columnconfigure(1, weight = 1)
root.rowconfigure(1, weight = 2)
root.mainloop()
我試過這段代碼,但是當我把 cursor 放在上面時,按鈕顏色會自動改變,我也嘗試過使用(activebackground)但它仍然一樣:/,如何解決這個問題?
style.map("TButton", foreground=[('!active', 'white'), ('active', 'white')], background=[('!active', 'red'), ('active', 'red')], font = [('!active', ('Arial', 30, 'bold')), ('active', ('Arial', 30, 'bold'))])
沒關系,這段代碼解決了問題::)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.