Tkinter Button does not appear on TopLevel?

后端 未结 1 1982
无人及你
无人及你 2021-01-24 10:30

This is a piece of code I write for this question: Entry text on a different window?

It is really strange what happened at mySubmitButton, it appears that

相关标签:
1条回答
  • 2021-01-24 11:06

    I see the hello button, but I'm on windows 7.

    I did a quick re-write of your example. I'll be curious if it makes any difference for you.

    import tkinter as tk
    
    class GUI(tk.Tk):
        def __init__(self):
            tk.Tk.__init__(self)
    
            mainLabel = tk.Label(self, text='Example for pop up input box')
            mainLabel.pack()
    
            mainButton = tk.Button(self, text='Click me', command=self.on_click)
            mainButton.pack()
    
            top = self.top = tk.Toplevel(self)
            myLabel = tk.Label(top, text='Enter your username below')
            myLabel.pack()
    
            self.myEntryBox = tk.Entry(top)
            self.myEntryBox.pack()
    
            mySubmitButton = tk.Button(top, text='Hello', command=self.send)
            mySubmitButton.pack()
    
            top.withdraw()
    
        def send(self):
            self.username = self.myEntryBox.get()
            self.myEntryBox.delete(0, 'end')
            self.top.withdraw()
            print(self.username)
    
        def on_click(self):
            self.top.deiconify()
    
    gui = GUI()
    gui.mainloop()
    
    0 讨论(0)
提交回复
热议问题