简体   繁体   English

在 oop python 中使用 Tkinter 主题

[英]Using Tkinter Themes in oop python

I'm trying to use ttkthemes but for some reason when I import it i just get errors, It's telling me AttributeError: module 'ttkthemes.themed_tk' has no attribute 'Tk' so I tried changing Tk to ThemedTk but it still didn't work, thanks for any help in advance.我正在尝试使用 ttkthemes,但由于某种原因,当我导入它时,我得到了错误,它告诉我AttributeError: module 'ttkthemes.themed_tk' has no attribute 'Tk'所以我尝试将 Tk 更改为 ThemedTk 但它仍然没有工作,提前感谢您的帮助。 Here's the original code这是原始代码

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


That's because you used from ttkthemes import themed_tk as tk .那是因为您使用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 .) 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 。)

You could use from ttkthemes import themed_tk as [another_name] then do what you want.你可以使用from ttkthemes import themed_tk as [another_name]然后做你想做的事。

You overwrote your tk wich represents the tkinter module with ttkthemes.themed_tk .您用ttkthemes.themed_tk覆盖了代表tkinter模块的tk

tk.Tk being the window of tkinter module you can't access it anymore tk.Tktkinter模块的 window 你不能再访问它了

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

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