Skip to content Skip to sidebar Skip to footer

Tkinter Button Does Not Appear On Toplevel?

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

Solution 1:

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

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

    defsend(self):
        self.username = self.myEntryBox.get()
        self.myEntryBox.delete(0, 'end')
        self.top.withdraw()
        print(self.username)

    defon_click(self):
        self.top.deiconify()

gui = GUI()
gui.mainloop()

Post a Comment for "Tkinter Button Does Not Appear On Toplevel?"