我正在尝试设置按钮的样式,以使其在单击时变色。这给我一个错误,即找不到我存储了样式的变量stylebutton
。如何正确分配此变量?
这是用于较大的Tkinter GUI。
stylebutton = ttk.Style()
stylebutton.map("stylebutton",
foreground=[('pressed', 'red'), ('active', 'blue')],
background=[('pressed', '!disabled', 'black'), ('active''white'))
button = ttk.Button(self, text="Login as a student", style =
"stylebutton",command=lambda: controller.show_frame(PageOne))
我希望按钮会更改颜色,但是程序无法运行并给出错误代码:
回溯(最近通话最近):
File "C:/Users/LENOVO/PycharmProjects/CSinternal/LearnIt.py", line 1263, in <module> app = LearnIt() File "C:/Users/LENOVO/PycharmProjects/CSinternal/LearnIt.py", line 73, in __init__ frame = F(container, self,) File "C:/Users/LENOVO/PycharmProjects/CSinternal/LearnIt.py", line 122, in __init__ command=lambda: controller.show_frame(PageOneS)) File "C:\Users\LENOVO\AppData\Local\Programs\Python\Python36-32\lib\tkinter\ttk.py", line 614, in __init__ Widget.__init__(self, master, "ttk::button", kw) File "C:\Users\LENOVO\AppData\Local\Programs\Python\Python36-32\lib\tkinter\ttk.py", line 559, in __init__ tkinter.Widget.__init__(self, master, widgetname, kw=kw) File "C:\Users\LENOVO\AppData\Local\Programs\Python\Python36-32\lib\tkinter\__init__.py", line 2293, in __init__ (widgetName, self._w) + extra + self._options(cnf)) _tkinter.TclError: Layout stylebutton not found