Skip to content Skip to sidebar Skip to footer

Tkinter Widgets Not Appearing

I was testing an app I was writing but I just get a blank window and no widgets. from Tkinter import* class App(Frame): def _init_(self, master): frame = Frame(master) fr

Solution 1:

You have a couple of typos. The first is in the name of the constructor method:

def_init_(self, master):

Should read:

def__init__(self, master):

Note the double underscore - see the docs for Python objects.

The second is inside your constructor:

frane.pack()

You're also missing a declaration for a method named 'reveal' in your App class:

self.button = Button(frame, text="Enter", command=self.reveal)

The working example reads:

from Tkinter import *

class App(Frame):

    def __init__(self, master):
        Frame.__init__(self, master)
        self.pack()

        frame = Frame()
        frame.pack()

        self.instruction = Label(frame, text="Password:")
        self.instruction.pack()

        self.button = Button(frame, text="Enter", command=self.reveal)
        self.button.pack()


    def reveal(self):
        # Do something.
        pass


root = Tk()
root.title("Password")
root.geometry("350x250")
App(root)
root.mainloop()

See also: The Tkinter documentation.

Post a Comment for "Tkinter Widgets Not Appearing"