updating text after running mainloop in tkinter updating text after running mainloop in tkinter tkinter tkinter

updating text after running mainloop in tkinter


The code after mainloop() gets called only after your applications is closed. So after the application is closed, the method is called, but the widgets used in the method is destroyed. So change your code to:

monitor = Monitor()monitor.loginfo()monitor.root.mainloop()

This way, the function is called before you exit the GUI. Think of mainloop() as a while loop that keeps updating till the window is closed. Technically saying mainloop() is same as:

while True: # Only exits, because update cannot be used on a destroyed application    root.update()    root.update_idletasks()

Edit:Since you wanted a delay, you have to add a button or something that calls this method while the GUI is active, an example is to use after to show the function after some time, like:

monitor = Monitor()monitor.root.after(1000,monitor.loginfo) # Cause a delay of 1 second or 1000 millisecond monitor.root.mainloop()