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 the button does not want to appear when it is first started, it will, however appear when you click on it. Even if you click on it and release it away from the button, that way it won't be send. I am suspecting if this only happen on a mac, or it only happen to my computer, because it is a very minor problem. Or it is something silly I did with my code.
self.mySubmitButton = tk.Button(top, text='Hello', command=self.send)
self.mySubmitButton.pack()
Am I missing something? I googled and found this question and answer on daniweb. And I do a diff on them, can't figure out what he did "fixed", but I did see the line is changed to command=root.quit
. But it is different from mine anyway...
Here is the full source code, and there is no error message, but the button is just missing.
import tkinter as tk
class MyDialog:
def __init__(self, parent):
top = self.top = tk.Toplevel(parent)
self.myLabel = tk.Label(top, text='Enter your username below')
self.myLabel.pack()
self.myEntryBox = tk.Entry(top)
self.myEntryBox.pack()
self.mySubmitButton = tk.Button(top, text='Hello', command=self.send)
self.mySubmitButton.pack()
def send(self):
global username
username = self.myEntryBox.get()
self.top.destroy()
def onClick():
inputDialog = MyDialog(root)
root.wait_window(inputDialog.top)
print('Username: ', username)
username = 'Empty'
root = tk.Tk()
mainLabel = tk.Label(root, text='Example for pop up input box')
mainLabel.pack()
mainButton = tk.Button(root, text='Click me', command=onClick)
mainButton.pack()
root.mainloop()
- Adding another button right after this one, the second one actually appear. I thought it might be because I didn't call the same function, but I called the same one and it does the exact same thing it appears...
- Adding a empty label between them, doesn't work. The button still isn't being draw.
PS: I am using Mac OS 10.5.8, and Tk 8.4.7.