[英]AttributeError: module 'tkinter' has no attribute 'tk'
[英]AttributeError: module 'tkinter.ttk' has no attribute 'Tk'
我最近为我的 tkinter 项目安装了 ttkthemes package,所以我认为我的代码中说tk
的所有内容都应该替换为ttk
,但由于某种原因,我收到错误AttributeError: module 'tkinter.ttk' has no attribute 'Tk
。 请帮助,感谢您提前提供任何帮助。 这是我的代码:
from tkinter import *
from tkinter import ttk
from ttkthemes import themed_tk as tk
class SeaofBTCapp(ttk.Tk):
def __init__(self, *args, **kwargs):
ttk.Tk.__init__(self, *args, **kwargs)
container = ttk.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 (Task, YourAdressess):
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):
# for frame in self.frames.values():
# frame.grid_remove()
frame = self.frames[cont]
frame.ttkraise()
frame.winfo_toplevel().geometry("1024x720")
frame.configure(bg='#333130')
class Task(ttk.Frame):
def __init__(self, parent, controller):
ttk.Frame.__init__(self, parent)
c = Canvas(self, height=50, width=102400, bg="#333130")
c.pack()
taskbutton = ttk.Button(self, text='Task', command=lambda: controller.show_frame(Task))
taskbutton_window = c.create_window(10, 12.5, anchor=ttk.NW, window=taskbutton)
adressbutton = ttk.Button(self, text='Your Adressess', command=lambda: controller.show_frame(YourAdressess))
adressbutton_window = c.create_window(104, 12.5, anchor=ttk.NW, window=adressbutton)
class YourAdressess(ttk.Frame):
def __init__(self, parent, controller):
ttk.Frame.__init__(self, parent)
c = Canvas(self, height=50, width=1024, bg="#333130")
c.pack()
taskbutton = ttk.Button(self, text='Task', command=lambda: controller.show_frame(Task))
taskbutton_window = c.create_window(10, 12.5, anchor=ttk.NW, window=taskbutton)
adressbutton = ttk.Button(self, text='Your Adressess', command=lambda: controller.show_frame(YourAdressess))
adressbutton_window = c.create_window(104, 12.5, anchor=ttk.NW, window=adressbutton)
app = SeaofBTCapp()
app.mainloop()
该错误准确地告诉您出了什么问题。 ttk 没有名为Tk
的 class 。 您必须使用来自 tkinter 模块的那个。
由于您对 tkinter 进行了通配符导入,因此您可以使用Tk
:
class SeaofBTCapp(Tk):
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.