微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在面向对象编程中使用tkinter主题

如何解决如何在面向对象编程中使用tkinter主题

所以我想给我的tkinter应用一个主题。但是,我不确定如何将其实现为像标准tkinter一样的类。这是我的代码

import tkinter as tk
from tkinter import ttk
from ttkthemes import ThemedTk


class Gui(tk.Tk): # where do I put ThemedTk
    def __init__(self):
        super().__init__()
        self.title('TThack')
        self.geometry('200x440')

        self.type = tk.StringVar()
        self.status_message = tk.StringVar()
        self.coins_message = tk.StringVar()
        self.school_label = tk.Label(text="School",justify="left")
        self.school_entry = tk.Entry()
        self.username_label = tk.Label(text="Username")
        self.username_entry = tk.Entry()
        self.password_label = tk.Label(text="Password")
        self.password_entry = tk.Entry()
        self.rounds_label = tk.Label(text="Number Of Rounds")
        self.rounds_entry = tk.Entry()
        self.type_label = tk.Label(text="Game Mode")
        self.name_entry = tk.Entry(self)
        self.type_entry_one = tk.Radiobutton(text="Garage",value="garage",variable=self.type,command=self.disable_entry)
        self.type_entry_two = tk.Radiobutton(text="Festival",value="festival",command=self.disable_entry)
        self.type_entry_three = tk.Radiobutton(text="Studio",value="studio",command=self.disable_entry)
        self.type_entry_five = tk.Radiobutton(text="Soundcheck",value="soundcheck",command=self.disable_entry)
        self.type_entry_six = tk.Radiobutton(text="Arena",value="arena",command=self.disable_entry)
        self.type_entry_four = tk.Radiobutton(text="Rockslam",value="rockslam",command=self.enable_entry)
        self.type.set('garage')
        self.submit = tk.Button(text="Start Hack",command=self.send_values)
        self.end = tk.Button(text="End Hack",command=bot.end)
        self.coins = tk.Label(textvariable=self.coins_message)
        self.coins_message.set('Coins Earned So Far: 0')
        self.status = tk.Label(textvariable=self.status_message)
        self.status_message.set('Waiting...')
        self.school_label.pack(anchor="w")
        self.school_entry.pack(anchor="w")
        self.username_label.pack(anchor="w")
        self.username_entry.pack(anchor="w")
        self.password_label.pack(anchor="w")
        self.password_entry.pack(anchor="w")
        self.rounds_label.pack(anchor="w")
        self.rounds_entry.pack(anchor="w")
        self.type_label.pack(anchor="w")
        self.type_entry_one.pack(anchor="w")
        self.type_entry_two.pack(anchor="w")
        self.type_entry_three.pack(anchor="w")
        self.type_entry_five.pack(anchor="w")
        self.type_entry_six.pack(anchor="w")
        self.type_entry_four.pack(anchor="w")
        self.submit.pack(anchor="w")
        self.end.pack(anchor="w")
        self.coins.pack(anchor="w")
        self.status.pack(anchor="w")

#there are more functions below,however I won't show them just to make this shorter.

根据the docs,我需要在代码中实现类似以下内容

from tkinter import ttk  # normal Tkinter.* widgets are not themed!

from ttkthemes import ThemedTk

window = ThemedTk(theme="arc")
ttk.Button(window,text="Quit",command=window.destroy).pack()
window.mainloop()

那么我将如何在课堂上做到这一点?甚至有可能吗?

编辑:this post对我没有帮助。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。