EDUCBA

EDUCBA

MENUMENU
  • Explore
    • Lifetime Membership
    • All in One Bundles
    • Fresh Entries
    • Finance
    • Data Science
    • Programming and Dev
    • Excel
    • Marketing
    • HR
    • PDP
    • VFX and Design
    • Project Management
    • Exam Prep
    • All Courses
  • Blog
  • Enterprise
  • Free Courses
  • Login
Home Software Development Software Development Tutorials Tkinter Tutorial Tkinter after

Tkinter after

Sivaraman V
Article bySivaraman V
Priya Pedamkar
Reviewed byPriya Pedamkar

Updated May 31, 2023

Tkinter after

Introduction to Tkinter after

The Tkinter after() is one of the methods for the Tkinter package, and this method is used to calculate the time intervals for the functions in the application parallel. It calculates the time using milliseconds format whether the widget seems delayed since the Tkinter is a GUI-based library. If we have no particular values of the explicit statement, it goes to the default state behavior.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

Syntax

The most powerful GUI-based widget has the most advanced library methods in Python. It has more global strategies; hence after(), one of the international methods can be used directly on the specific root functions of the widget or application. It has its own syntax and default parameters.

from tkinter import Tk //import the library in python
from tkinter.ttk import Button //import the library in python
variablename =functionName() //Tk library function
variablename.after(time(if it’s in delay status or not),callback)
--some python code logics---

In the above code, we used first to import the specific libraries, and we declared one variable name with the specific function. If it is in delay, then it will be executed at another time interval.

How does it Work?

Tkinter package has a set of built-in functions that have been used for covering the UI parts in the web application. It has the most interactive and advanced library. Basically, we want to decorate the UI has buttons, views, scroll box, etc most buttons will be the UI area to navigate the web pages or applications. Once we click the button, it operates and works the backend areas. We also calculate the time intervals in Chrome or some other browsers if it seems to be a web-based application. For example, we have not given delay times or callback argument values. The callback has taken the None value delay argument as a default called sleep() method of the Python code. Also, it has taken milliseconds as the time format instead of the seconds.

The after() method also calls all the widgets of the Python apps. It will be supported on multiple OS like Windows, Linux, etc. It is a standard library also; we can create desktop-based applications using Python Tkinter also; it’s not a complex task. We can use the Tkinter basic widgets like “Button,Canvas,Checkbutton,Frame,Label,Listbox,Menu,Message,Radiobutton,Text, etc” These widgets are mostly covered in the UI part, and these widget packages utilize the method called after() in all the widgets. Mostly time-related logic has been covered, and the multi-threading applications are also the most important part of this particular method in the library. It has separate modules, and it has its own interface.

Examples of Tkinter after

Lets us discuss the examples.

Example 1

from tkinter import *
from time import time
from tkinter.ttk import Button
demos= Tk()
b = Button(demos, text = 'Welcome To My Domain')
b.pack(pady = 77,side = TOP)
pink = Button(demos, text = "pink")
pink.pack( side = TOP)
green = Button(demos, text = "green")
green.pack( side = BOTTOM )
violet = Button(demos, text = "violet")
violet.pack( side = LEFT )
yellow = Button(demos, text = "yellow")
yellow.pack( side = RIGHT)
print('The Tk Widget is running on the screen...')
startingtime = time()
demos.after(200000, demos.destroy)
demos.mainloop()
endingtime = time()
print('The Tk Widget is closed after % d seconds' % (endingtime-startingtime))

Output:

tkinter after 1-1

Example 2

from tkinter import *  
user = Tk()  
uname = Label(user,text = "uname").grid(row =0, column = 0)  
un= Entry(user).grid(row = 0, column = 0)  
passw = Label(user,text = "pass").grid(row = 1, column = 1)  
ps = Entry(user).grid(row = 1, column = 1)  
result = Button(user, text = "submit").grid(row = 3, column = 3)  
user.mainloop() 
try:
    import tkinter as tk
except ImportError:
    import Tkinter as tk
class Timer:
    def __init__(first, second):
        first.seconds = 1
        first.label = tk.Label(second, text="1s", font="Arial 25", width=17)
        first.label.pack()
        first.label.after(3000, first.demo)
    def demo(first):
        first.seconds += 1
        first.label.configure(text="%i s" % first.seconds)
        first.label.after(2000, first.demo)
if __name__ == "__main__":
    demos = tk.Tk()
    tme = Timer(demos)
    demos.mainloop() 

Output:

tkinter after 1-2

tkinter after 1-3

Example 3

from tkinter import Tk, mainloop, TOP
from tkinter.ttk import Button
from tkinter.messagebox import _show
sample = Tk()
btn = Button(sample, text = 'Welcome To my Domain')
btn.pack(side = TOP, pady = 7)
b2 = Button(sample, text = 'Welcome To my Domain')
b2.pack(side = TOP, pady = 7)
b3 = Button(sample, text = 'Welcome To my Domain')
b3.pack(side = TOP, pady = 7)
b4 = Button(sample, text = 'Welcome To my Domain')
b4.pack(side = TOP, pady = 7)
sample.after(3400, lambda : _show('user', 'Have a Nice Day'))
sample.after(5400, sample.destroy)
btn.pack(side = TOP, pady = 7)
b5 = Button(sample, text = 'Welcome To my Domain')
b5.pack(side = TOP, pady = 7)
b6 = Button(sample, text = 'Welcome To my Domain')
b6.pack(side = TOP, pady = 7)
b7 = Button(sample, text = 'Welcome To my Domain')
b7.pack(side = TOP, pady = 7)
mainloop()
b8 = Button(sample, text = 'Welcome To my Domain')
b8.pack(side = TOP, pady = 7)
b9 = Button(sample, text = 'Welcome To my Domain')
b9.pack(side = TOP, pady = 7)
b10 = Button(sample, text = 'Welcome To my Domain')
b10.pack(side = TOP, pady = 7)
mainloop()

Output:

Example 3

Example 3-1

Conclusion

The after() method is a function available in the Tkinter library of Python that allows the creation of various GUI presentations. Tkinter is a popular library for building graphical user interfaces (GUIs) in Python. It provides a user-friendly approach to GUI development. Likewise, the Python library has default methods to create UI widgets in desktop and web-based applications.

Recommended Articles

This is a guide to Tkinter after. Here we discuss the Introduction and working along with different examples and code implementation. You may also have a look at the following articles to learn more –

  1. Tkinter Menubutton
  2. Tkinter Text
  3. Tkinter Widgets
  4. Python Tkinter Button
ADVERTISEMENT
All in One Excel VBA Bundle
500+ Hours of HD Videos
15 Learning Paths
120+ Courses
Verifiable Certificate of Completion
Lifetime Access
ADVERTISEMENT
Financial Analyst Masters Training Program
2000+ Hours of HD Videos
43 Learning Paths
550+ Courses
Verifiable Certificate of Completion
Lifetime Access
ADVERTISEMENT
All in One Data Science Bundle
2000+ Hour of HD Videos
80 Learning Paths
400+ Courses
Verifiable Certificate of Completion
Lifetime Access
ADVERTISEMENT
All in One Software Development Bundle
5000+ Hours of HD Videos
149 Learning Paths
1050+ Courses
Verifiable Certificate of Completion
Lifetime Access
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2023 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

🚀 Extended Cyber Monday Price Drop! All in One Universal Bundle (3700+ Courses) @ 🎁 90% OFF - Ends in ENROLL NOW