[英]unable to change button color on tkinter top-level using hightlightbackground
Below is a working example of the problem. 下面是该问题的一个有效示例。 You press the first button and the top-level opens with non colored button.
您按第一个按钮,顶层将打开,并带有非彩色按钮。 Thanks!
谢谢!
import tkinter as tk
class MainGui:
def __init__(self,root):
self.root=root
self.main_frame=tk.Frame(root)
self.button1=tk.Button(self.main_frame,text='open top level',
highlightbackground='green',command=self.open_top,font=
('helvetica',24))
self.button1.grid(row=0,column=0)
self.main_frame.grid(row=1,column=1)
def open_top(self):
class TopLevel:
def __init__(self,root):
self.root = root
self.top_frame = tk.Frame(root)
self.button2 = tk.Button(self.top_frame, text='not
colored',highlightbackground='green', font=
('helvetica', 24))
self.button2.grid(row=1,column=1)
self.top_frame.grid(row=1,column=1)
root=tk.Toplevel()
app=TopLevel(root)
root=tk.Tk()
app=MainGui(root)
root.mainloop()
The colors appear correctly when clicking off the gui or in other words somewhere else on desktop. 单击gui或换句话说,在桌面上的其他位置时,颜色正确显示。 Clicking on the gui results in colors going back to grey
单击gui会导致颜色变回灰色
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.