我是Tkinter / OOP的新手并希望得到一些帮助,我目前无法为应用程序制作gui . 我想要的功能是当一个使用TopLevel()小部件的新窗口产生时,用于它的按钮被禁用,这是我已经实现的 . 但问题是在生成的窗口关闭后启用它 .

一般来说,如何使用基于OOP的方法从TopLevel()小部件修改主tkinter根窗口 . 因为我想稍后做更多的事情

代码如下:

from tkinter import *
from tkinter import ttk

class MainWindow:
    def __init__(self, top):

        _bgcolor = '#d9d9d9'  # X11 color: 'gray85'
        _fgcolor = '#000000'  # X11 color: 'black'
        _compcolor = '#d9d9d9'  # X11 color: 'gray85'
        _ana1color = '#d9d9d9'  # X11 color: 'gray85'
        _ana2color = '#d9d9d9'  # X11 color: 'gray85'
        font10 = "-family {Segoe UI} -size 10 -weight normal -slant " \
                 "roman -underline 0 -overstrike 0"
        self.style = ttk.Style()
        if sys.platform == "win32":
            self.style.theme_use('winnative')
        self.style.configure('.', background=_bgcolor)
        self.style.configure('.', foreground=_fgcolor)
        self.style.configure('.', font="TkDefaultFont")
        self.style.map('.', background=
        [('selected', _compcolor), ('active', _ana2color)])

        self.top=top
        self.top.geometry("214x96+462+349")
        self.top.title("Test")
        self.top.configure(background="#d9d9d9")
        self.top.configure(highlightbackground="#d9d9d9")
        self.top.configure(highlightcolor="black")
        self.top.resizable(0, 0)

        self.Btn_UI = Button(self.top)
        self.Btn_UI.place(relx=0.50, rely=0.21, height=24, width=100)
        self.Btn_UI.configure(activebackground="#d9d9d9")
        self.Btn_UI.configure(activeforeground="#000000")
        self.Btn_UI.configure(background="#d9d9d9")
        self.Btn_UI.configure(command=self.Btn_UI_fun)
        self.Btn_UI.configure(disabledforeground="#a3a3a3")
        self.Btn_UI.configure(foreground="#000000")
        self.Btn_UI.configure(highlightbackground="#d9d9d9")
        self.Btn_UI.configure(highlightcolor="black")
        self.Btn_UI.configure(pady="0")
        self.Btn_UI.configure(text='''New Window''')

    def Btn_UI_fun(self):
        print('button')
        root2 = Toplevel(self.top)
        second = SettingsWindow(root2)
        self.Btn_UI.configure(state="disabled")
        return 

class SettingsWindow():

    def __init__(self, master):
        self.master=master
        self.master.geometry("214x96+462+349")
        self.master.title("New")
        self.master.configure(background="#d9d9d9")
        self.master.configure(highlightbackground="#d9d9d9")
        self.master.configure(highlightcolor="black")
        self.master.resizable(0, 0)

        self.Btn = Button(self.master)  
        self.Btn.place(relx=0.50, rely=0.21, height=24, width=51)
        self.Btn.configure(text='''Quite''')
        self.Btn.configure(command=self.quite)

    def quite(self):
        p = MainWindow.__init__
        p.self.Btn_UI.configure(state="normal")
        self.master.destroy()

def main():
    root = Tk()
    Main = MainWindow(root)
    root.mainloop()

main()

提前致谢!! :d