Tkinter Python Clock Designing Tutorial For Beginners

tkinter python

Description:

Tkinter python clock designing tutorial for beginners- this is a very basic and detail tutorial about how to design a clock in python using Tkinter widget. If you don’t know how to make a python GUI so I create a detailed tutorial in which I worked on buttons and drawing shapes using Tkinter canvas so visit this tutorial python GUI.



Tkinter python clock:

first we import the tkinter module for showing  python GUI and then we import time then we create the root window root is equal to Tk() then we are going to set the geometry of our massive in your root.geometry 600 x 200+350+300 now what does this mean this means 600 means the distance from this point

tkinter python

to this point

tkinter python

horizontal distance so the window is 600 units or pixels in width.

tkinter python

and 200 pixels in height.

350 is the distance from left a border so this is from here

tkinter python

tkinter python

the distance is 350 where the window is created and 300 is the distance from top and this is 300 so this is distance is 350 and this distance is 300 after the Tkinter python window is created you can move it anywhere and there shouldn’t be any problem.


To set the window title for that we have an attribute title in Tkinter python

tkinter python

you can see the title is change form tk to python clock designing

then we create the clock frame which is a frame in python GUI and we give it the argument root width is 200 height is 100 background color with green and relief is groove and then we pack it with the syntax called cframe.pack().



then we create a label in tkinter python which called clock so clock is a label and we attached this label to cframe and pad X is 25 pad Y is 40 bd is 3 foreground is dark green color font his Ariel 48 and bold text is timenow which is empty for the time being and background with light green and relief is sunken and we packed this clock here pad X is the horizontal padding around the text and pad y is the vertical padding and BD is the border width FG is foreground color font Arial 48 bold and background color is light green and relief is sunken and then we pack it with the syntax called clock.pack().

in the function we initialize the the global variable timenow which is already define in start.then timenow is assign to the attribute time. strftime(‘%H: %M: %S %p’) and this is the formatting of time. then if newtime is not timenow. timenow should be new time so this is changing time. then we configure the clock and text is applied as timenow so constantly changing the time and updating the time clock after 200 takes so after 200 milliseconds the timer function is called and root.mainloop.


full and final Tkinter python clock code:


now run the tkinter python clock final code by pressing f5

tkinter python

please keep in mind in order to understand this piece of code you ought to have a basic understanding of Python programming language after that you can practice this thank you.

Recommended For You

Leave a Reply

%d bloggers like this: