在 oop python 中使用 Tkinter 主题 [英] Using Tkinter Themes in oop python

查看:63
本文介绍了在 oop python 中使用 Tkinter 主题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 ttkthemes,但由于某种原因,当我导入它时,我得到了错误,它告诉我 AttributeError: module 'ttkthemes.themed_tk' has no attribute 'Tk' 所以我试过了将 Tk 更改为 ThemedTk 但它仍然不起作用,提前感谢您的任何帮助.这是原始代码

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


推荐答案

你用 ttkthemes.themed_tktkinter 模块的 tk>.

You overwrote your tk wich represents the tkinter module with ttkthemes.themed_tk.

tk.Tktkinter 模块的窗口,你不能再访问它

tk.Tk being the window of tkinter module you can't access it anymore

这篇关于在 oop python 中使用 Tkinter 主题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆