+

Python | post method in Tkinter

Tkinter provides many built-in functions for developing an interactive and functional graphical user interface (graphical user interface). The after() function is also a generic function that can be used directly at the root, as well as with other widgets.

 after (parent, ms, function = None, * args) 

Parameters:
parent : is the object of the widget or main window whichever is using this function.
ms : is the time in miliseconds.
function : which shall be called.
* args : other options.

Code # 1:

# import only those functions that
# are required

from tkinter import Tk, mainloop, TOP

from   tkinter.ttk import Button

 
# timing function used to calculate timing

from time import time

 
# create a tkinter window

root = Tk ()

 

button = Button (root, text = `Geeks` )

button.pack (side = TOP, pady = 5 )

 

print ( `Running ...` )

# Calculate start time

start = time ()

 
# in 5000 milliseconds after the method
# passed i.e. in 5 seconds
# main window i.e. the root window will
# be destroyed

root.after ( 5000 , root.destroy)

 
mainloop ()

 
# calculate the end time

end = time ()

print ( `Destroyed after % d seconds` % (end - start))

Output:


When you run the program, it will show a Tkinter window with a

# only import functions that
# are required

from tkinter import Tk, mainloop, TOP

from tkinter.ttk import Button

from tkinter.messagebox import _ show

 
# create a tkinter window

root = Tk ()

root.geometry ( ` 200x100 + 300 + 250` )

 

button = Button (root, text = ` Geeks` )

button.pack (side = TOP, pady = 5 )

 
# in 5000 milliseconds after the method
# passed i.e. after 5 seconds
# message will be offered

root.after ( 5000 , lambda : _show ( `Title` , ` Prompting after 5 seconds` ))

 
# Destroying the root window after 6.7 seconds

root.after ( 6700 , root.destroy)

  
mainloop ()

Output:
In output below after 5 seconds a message box will appear where you can even call any function after a certain period of time by passing the name of the function.

Get Solution for free from DataCamp guru