[英]Using Tkinter Themes in oop python
我正在嘗試使用 ttkthemes,但由於某種原因,當我導入它時,我得到了錯誤,它告訴我AttributeError: module 'ttkthemes.themed_tk' has no attribute 'Tk'
所以我嘗試將 Tk 更改為 ThemedTk 但它仍然沒有工作,提前感謝您的幫助。 這是原始代碼
from tkinter import *
import tkinter as tk
from tkinter import ttk
from ttkthemes import themed_tk as tk
class SeaofBTCapp(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
container = tk.Frame(self)
container.pack(side="top", fill="both", expand=True)
container.grid_rowconfigure(0, weight=1)
container.grid_columnconfigure(0, weight=1)
self.frames = {}
for F in (StartPage,Task):
frame = F(container, self)
self.frames[F] = frame
frame.grid(row=0, column=0, sticky="nsew")
self.show_frame(StartPage)
def show_frame(self, cont):
frame = self.frames[cont]
frame.tkraise()
frame.winfo_toplevel().geometry("1024x720")
frame.configure(bg='#333130')
class StartPage(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
class Task(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
app = SeaofBTCapp()
app.mainloop()
那是因為您使用from ttkthemes import themed_tk as tk
。
When the next time you use tk.Tk()
, it could be themed_tk.Tk()
.Apparently, Tk
class is in the module tkinter
, not themed_tk
.(Although you has used import tkinter as tk
,it has been covered by from ttkthemes import themed_tk as tk
。)
你可以使用from ttkthemes import themed_tk as [another_name]
然后做你想做的事。
您用ttkthemes.themed_tk
覆蓋了代表tkinter
模塊的tk
。
tk.Tk
是tkinter
模塊的 window 你不能再訪問它了
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.