【发布时间】:2020-05-23 16:36:36
【问题描述】:
我最近为我的 tkinter 项目安装了 ttkthemes 包,所以我认为我的代码中提到的所有 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()
【问题讨论】: