python - Tkinter widgets not showing -


i'm beginner , getting tkinter basics. i'm following along tutorial, none of widgets appearing in window. no errors.

import tkinter  class pinger(tkinter.tk):     def __init__(self, parent):         tkinter.tk.__init__(self, parent)         self.parent = parent  def initialize(self):     self.grid()        button = tkinter.button(self,text="button")     button.grid(column=1,row=0)   if __name__ == "__main__":     app = pinger(none)     app.title('server pinger')     app.mainloop() 

the window opens without issue , no errors shown. button widget found, nor other widget try.

your issue according indentation function - initialize() - outside class . if function inside class , never call .

in python, indentation important , used defining blocks . , should call initialize() function inside init() function . example -

import tkinter  class pinger(tkinter.tk):     def __init__(self, parent):         tkinter.tk.__init__(self, parent)         self.parent = parent         self.initialize()      def initialize(self):         self.grid()         button = tkinter.button(self,text="button")         button.grid(column=1,row=0)   if __name__ == "__main__":     app = pinger(none)     app.title('server pinger')     app.mainloop() 

Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -