Search code examples
pythonpython-3.xbuttontkinterframe

Button doesn't show in the frame


I have created a couple of frames and now want to put some buttons and labels on them, but from the first button that I created, I am facing a problem. Nothing is showing in the tkinter window.

from tkinter import *

class STproject():

    def __init__(self,app): #1
        self.stframe=Frame(app,background='blue',height=90,width=350)
        self.stframe.grid(row=0,column=0)
        self.ndframe=Frame(app,background='red',height=90,width=350)
        self.ndframe.grid(row=1,column=0)
        self.rdframe=Frame(app,background='yellow',height=90,width=350)
        self.rdframe.grid(row=2,column=0)

        self.ndstframe=Frame(self.ndframe,background='black',width=145)
        self.ndstframe.grid(row=0,column=0,rowspan=3,sticky='ns')
        self.ndndframe=Frame(self.ndframe,background='white',height=45,width=205)
        self.ndndframe.grid(row=1,column=1)
        self.ndrdframe=Frame(self.ndframe,background='green',height=45,width=205)
        self.ndrdframe.grid(row=2,column=1)

    def buttons(self):
        self.importbutton=Button(self.stframe,text='Import',width=4,height=2)
        self.importbutton.grid(row=0,column=0)



root=Tk()
root.title('SteelBox Inc. Calculator')
application=STproject(root) #2
root.mainloop() #3

Solution

  • You have put the creating of the button in a separate function, but you never call it. Add self.buttons() at the end of the __init__ and the button will appear.