简体   繁体   English

AttributeError:模块“tkinter.ttk”没有属性“Tk”

[英]AttributeError: module 'tkinter.ttk' has no attribute 'Tk'

i recently installed the ttkthemes package for my tkinter project, and so i figured everything that says tk in my code should be replaced with ttk but for some reason i get the error AttributeError: module 'tkinter.ttk' has no attribute 'Tk .我最近为我的 tkinter 项目安装了 ttkthemes package,所以我认为我的代码中说tk的所有内容都应该替换为ttk ,但由于某种原因,我收到错误AttributeError: module 'tkinter.ttk' has no attribute 'Tk Please help, Thanks for any help in advance.请帮助,感谢您提前提供任何帮助。 Here's my code:这是我的代码:

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()

The error is telling you precisely what is wrong.该错误准确地告诉您出了什么问题。 ttk does not have a class named Tk . ttk 没有名为Tk的 class 。 You must use the one that comes from the tkinter module.您必须使用来自 tkinter 模块的那个。

Since you did a wildcard import of tkinter, you can use Tk :由于您对 tkinter 进行了通配符导入,因此您可以使用Tk

class SeaofBTCapp(Tk):

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM