Tkinter का उपयोग करके, हम GUI बना सकते हैं जिसे ऑटो-अपडेशन के लिए कॉन्फ़िगर किया जा सकता है। इस उद्देश्य के लिए, हम GUI- आधारित घड़ियाँ बनाएंगे जो समय बदलने पर स्वचालित रूप से ताज़ा हो जाएँगी। हम घड़ी को दिन और समय क्षेत्र के साथ प्रदर्शित करेंगे।
सबसे पहले, हम नोटबुक में टिंकर लाइब्रेरी आयात करेंगे, फिर हम एक फ़ंक्शन बनाएंगे जो “strftime” का उपयोग करके वर्तमान समय और दिन के उदाहरण बनाता है। समारोह।
उदाहरण
#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() आउटपुट
उपरोक्त कोड को चलाने से विंडो में स्वचालित रूप से अपडेट किया गया GUI एप्लिकेशन बन जाएगा।
