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