
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
How do I create an automatically updating GUI using Tkinter?
Using Tkinter, we can create GUI which can be configured for auto-updation. For this purpose, we will create GUI-based clocks that will automatically get refreshed when the time changes. We will display the clock along with the day and TimeZone.
First, we will import the tkinter library in the notebook, then we will create a function which creates instances of current time and day using the “strftime” function.
Example
#Import the tkinter library from tkinter import * import time #Create an instance of the canvas win = Tk() #Select the title of the window win.title("tutorialspoint.com") #Define the geometry of the window win.geometry("600x400") #Define the clock which def clock(): hh= time.strftime("%I") mm= time.strftime("%M") ss= time.strftime("%S") day=time.strftime("%A") ap=time.strftime("%p") time_zone= time.strftime("%Z") my_lab.config(text= hh + ":" + mm +":" + ss) my_lab.after(1000,clock) my_lab1.config(text=time_zone+" "+ day) #Update the Time def updateTime(): my_lab.config(text= "New Text") #Creating the label with text property of the clock my_lab= Label(win,text= "",font=("sans-serif", 56), fg= "red") my_lab.pack(pady=20) my_lab1= Label(win, text= "", font=("Helvetica",20), fg= "blue") my_lab1.pack(pady= 10) #Calling the clock function clock() #Keep Running the window win.mainloop()
Output
Running the above code will create an automatically updated GUI Application in the window.
- Related Articles
- How do I create an automatically updating GUI using Tkinter in Python?
- How to create an impressive GUI in Python using Tkinter?
- How do you create a Tkinter GUI stop button to break an infinite loop?
- How do I create a popup window using Tkinter?
- How do I create a popup window using Tkinter Program?
- Create a GUI to check domain availability using Tkinter
- Create a GUI to Get Domain Information using Tkinter
- How to create a directly-executable cross-platform GUI app using Python(Tkinter)?
- Ratio Calculator GUI using Tkinter
- How do I create a popup window in Tkinter?
- How do I create a date picker in tkinter?
- How do I create child windows with Python tkinter?
- Simple GUI calculator using Tkinter in Python
- Creating an automatically maximized tkinter window
- How to build a simple GUI calculator using tkinter in Python

Advertisements