在oop python中使用Tkinter主题
我正在尝试使用TTK主题,但由于某些原因,当我导入它时,我只是得到了错误,它告诉我在oop python中使用Tkinter主题,python,oop,tkinter,themes,Python,Oop,Tkinter,Themes,我正在尝试使用TTK主题,但由于某些原因,当我导入它时,我只是得到了错误,它告诉我AttributeError:module'TTK主题。themed_tk'没有属性“tk”,因此我尝试将tk更改为ThemedTk,但仍然无法工作,感谢您事先提供的帮助。 这是原始代码 from tkinter import * import tkinter as tk from tkinter import ttk from ttkthemes import themed_tk as tk class Se
AttributeError:module'TTK主题。themed_tk'没有属性“tk”
,因此我尝试将tk更改为ThemedTk,但仍然无法工作,感谢您事先提供的帮助。
这是原始代码
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()
这是因为您使用了ttkthemes import主题的
作为tk
下次使用tk.tk()
时,它可能是主题的
。显然,tk
类在模块tkinter
中,而不是主题的
(虽然您使用了导入tkinter作为tk
,但它已被从tkthemes导入主题的
主题的覆盖)
您可以使用ttkthemes import-moted_-tk中的
作为[另一个名称]
然后做您想做的事。这是因为您使用了ttkthemes import-moted_-tk中的作为tk
下次使用tk.tk()
时,它可能是主题的
。显然,tk
类在模块tkinter
中,而不是主题的
(虽然您使用了导入tkinter作为tk
,但它已被从tkthemes导入主题的
主题的覆盖)
您可以使用ttkthemes import-themes-themes-themes-moted\u-tk中的
作为[另一个名称]
,然后做您想做的事。您重写了tk
,它用ttkthemes.moted\u-tk
表示tkinter
模块
tk.tk
作为tkinter
模块的窗口,您无法再访问它您重写了tk
,它代表tkinter
模块,主题为tkthemes.tomed\u tk
tk.tk
作为tkinter
模块的窗口,您不能再访问它了将从ttkthemes import-themed_-tk作为tk
更改为从ttkthemes.themed_-tk import-themedk
更改为classseaoftcap(themed-tk)
和tk.tk.。\uu init(…)
改为主题tk.\uuu init\uuuuu(…)
将从TTK主题导入主题tk作为tk
改为从TTK主题导入主题tk
,然后将类seatOfTCApp(tk.tk)
改为类seatOfTCApp(主题tk)
和tk.tk.\uuuuuu init(…)改为。