我正在尝试使用ThemedTk,但由于某些原因,当我导入它时,我得到了错误,它告诉我AttributeError: module 'ttkthemes.themed_tk' has no attribute 'Tk',所以我试着将Tk改为ttkthemes,但它仍然不起作用,谢谢提前的帮助。以下是原始代码
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()发布于 2020-06-03 10:23:37
这是因为您使用了from ttkthemes import themed_tk as tk。
当您下次使用tk.Tk()时,它可能是themed_tk.Tk().Apparently,Tk类在模块tkinter中,而不是themed_tk中。(虽然您已经使用过import tkinter as tk,但from ttkthemes import themed_tk as tk已经介绍了它)。
你可以使用from ttkthemes import themed_tk as [another_name],然后做你想做的事情。
发布于 2020-06-03 10:24:48
您用ttkthemes.themed_tk覆盖了表示tkinter模块的tk。
tk.Tk是tkinter模块的窗口,您不能再访问它
https://stackoverflow.com/questions/62164128
复制相似问题