问题
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.
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()
回答1:
That's because you used 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.
回答2:
You overwrote your tk
wich represents the tkinter
module with ttkthemes.themed_tk
.
tk.Tk
being the window of tkinter
module you can't access it anymore
来源:https://stackoverflow.com/questions/62164128/using-tkinter-themes-in-oop-python