简体   繁体   中英

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()

i've tried this code but the button color automatically change when i put the cursor on it, i've also tried to use (activebackground) but it still the same:/, how to solve that?

style.map("TButton", foreground=[('!active', 'white'), ('active', 'white')], background=[('!active', 'red'), ('active', 'red')], font = [('!active', ('Arial', 30, 'bold')), ('active', ('Arial', 30, 'bold'))])

it's ok, this code solved the problem: :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM