Hello!

My application is crashing randomly, and I thought it might have to do with it manipulating widgets that are not yet mapped, despite them being already gridded. Have you experienced this problem?

I supply some code that shows that the print function happens before tkinter recognizes the button being mapped, even though it is already gridded. I couldn't find a way to wait for the button being properly mapped before the print function is executed.

from tkinter import *

class fb( Frame ):
    def fastbuttons( self ):
        b = Button(self)
        b.grid()
        print( b.winfo_ismapped() )

    def __init__( self, master=None ):
        Frame.__init__( self, master )
        self.grid( sticky='nsew' )
        self.button = Button( self, text='Start', command=self.fastbuttons )
        self.button.grid()
        
if __name__ == '__main__':
    root = Tk()
    app = fb( master=root )
    app.mainloop()

Call for update() as shown below:

from tkinter import *

class fb( Frame ):
    def fastbuttons( self ):
        b = Button(self)
        b.grid()
        self.update()
        print( b.winfo_ismapped() )

    def __init__( self, master=None ):
        Frame.__init__( self, master )
        self.grid( sticky='nsew' )
        self.button = Button( self, text='Start', command=self.fastbuttons )
        self.button.grid()
        
if __name__ == '__main__':
    root = Tk()
    app = fb( master=root )
    app.mainloop()

Indeed it works. Thanks for help.

Yet, wonder if this will help my crash prevention...

This question has already been answered. Start a new discussion instead.