我使用了一个名为"forest-light“的主题,正如它在github上的作者所建议的那样实现的。一般来说,在我尝试为其他小部件使用几个布局之前,它的工作效果很好:
import tkinter as tk
from tkinter import ttk
class App(tk.Tk):
def __init__(self):
super().__init__()
ttk.Checkbutton(self, text="Checkbutton", style="ToggleButton").pack()
root = App()
root.tk.call('source', 'forest-light.tcl')
ttk.Style().theme_use('forest-light')
root.mainloop()我总是会犯错误:
_tkinter.TclError: Layout ToggleButton not found如果我在没有类的情况下做同样的事情,它的工作原理是:
import tkinter as tk
from tkinter import ttk
root = tk.Tk()
root.tk.call('source', 'forest-light.tcl')
ttk.Style().theme_use('forest-light')
ttk.Checkbutton(root, text="Checkbutton", style="ToggleButton").pack()
root.mainloop()如有任何见解或帮助,将不胜感激。
发布于 2022-08-10 01:00:36
在第一种情况下,在导入样式并使用它之前,您尝试使用ToggleButton样式:
root = App() # this is where you use the style
root.tk.call('source', 'forest-light.tcl') # this is where you import it.在第二种情况下,在创建ttk.Checkbutton之前导入样式。
root.tk.call('source', 'forest-light.tcl') # this is where you import it
ttk.Checkbutton(..., style="ToggleButton") # this is where you use it.https://stackoverflow.com/questions/73299547
复制相似问题