需要关闭现有的根并从Class激活主窗口根

时间:2019-06-01 16:57:31

标签: python-3.x tkinter

我已经为用户创建了一个“新建”按钮,以便启动主窗口。因此,我关闭了现有的根目录并获得了一个从Class初始化的新窗口。但是,这行不通吗?

def wnew():
    global root
    root= Tk()
    root.withdraw()
    root.destroy()
    Root.__init__(self)


#-----------------------------------------------------------------------------    
def Response_Frame(inp,out):

    root = Tk()
    root.style.configure("BW.TLabel", foreground="white", background="gray")
    root.columnconfigure(0, weight=1) # 100%
    root.rowconfigure(0, weight=1) # 10%
    root.rowconfigure(1, weight=8) # 80%
    root.rowconfigure(2, weight=1) # 10%


    root.menu_btn = ttk.Menubutton (root, text="File")
    root.menu_btn.menu = Menu(root.menu_btn, tearoff=0)
    root.menu_btn["menu"] = root.menu_btn.menu
    root.menu_btn.menu.add_command(label="New", command=wnew)
    root.menu_btn.menu.add_command(label="Help", command=whelp)
    root.menu_btn.menu.add_command(label="About", command=wabout)
    root.menu_btn.menu.add_command(label="Exit", command=wquit)

class Root(Tk):

    def __init__(self):
        super(Root,self).__init__() 
        self.title("Macro Parser")
        self.minsize(800,500)
        self.wm_iconbitmap('parser.ico')
        self.style = ttk.Style()
        self.style.configure("BW.TLabel", foreground="white", background="gray")
        self.columnconfigure(0, weight=1) # 100%
        self.rowconfigure(0, weight=1) # 10%
        self.rowconfigure(1, weight=8) # 80%
        self.rowconfigure(2, weight=1) # 10%
        self.Main_Frame()

    def Main_Frame(self):

        self.menu_btn = ttk.Menubutton (self, text="File")
        self.menu_btn.menu = Menu(self.menu_btn, tearoff=0)
        self.menu_btn["menu"] = self.menu_btn.menu
        self.menu_btn.menu.add_command(label="Help", command=whelp)
        self.menu_btn.menu.add_command(label="About", command=wabout)
        self.menu_btn.menu.add_command(label="Exit", command=wquit)
        self.menu_btn.grid(column = 0,row = 0, padx=5, pady=5,sticky='NW')

0 个答案:

没有答案