Step by Step Procedure to create Digital clock using Python
Hello friends how are you, Today in this post "Digital clock using Python" i am going to teach you how you can create a Digital Clock in Python using very simple lines of code. If you are a computer science students or teacher and want to learn something interesting in programming then just go through this post.
If you want to understand this through video then watch this video i have explained it step by step live
Step 1: Install Python : Click here to watch a video on how to install python or Open any browser and type Download Python and click the first link you will get official website of python here you will get a Download button and after clicking on this button you will get exe of latest python version just install it into your system.
Step 2: Install Pycharm | Create Project | Install Library: Click here to watch a single video on How to install Pycharm | Create Project | Install Library or To install Pycharm IDE Open any browser and type Download Pycharm and click the first link you will get official website of Pycharm here you will get a black download button and after clicking on this button you will get an exe of Pycharm , just install it into your system. If you are facing problem to install then watch the above video i have explained step by step.
Step 3: Create Project : Open Pycharm click on File which is in top left of screen and select New Project. Then you will get a screen. Here first you need to select directory of your project and then type a name for your project like "DigitalClock" after directory name, and at last click the create button to create this project.
Step 4: Create Python file: To create a python file for coding in your project just right click on project name "DigitalClock" and select new and click on Python File , you will get popup screen in which you have to type a name like "Program" for python file and press enter, it will create a python file with name Program.py inside the project DigitalClock.
import library: Here in this step we will import the needed library that will be used to create Digital Clock.
from tkinter import * from time import strftime
def time(): str=strftime("%H : %M : %S %p") lbl.config(text=str) lbl.after(1000,time)
myWindow=Tk() myWindow.title("Digital Clock") lbl=Label(myWindow,font=("Algerian",100),background="black",foreground="cyan") lbl.pack()
time() mainloop()
#import library #tkinter library to create GUI Window from tkinter import * #time library to get current system time from time import strftime #define function to get current time def time(): #get current time in given format str=strftime("%H : %M : %S %p") #passing time to label lbl.config(text=str) #refresh label every second lbl.after(1000,time) #creating GUI window myWindow=Tk() #setting title to window myWindow.title("Digital Clock") #creating label to dispaly digital clock lbl=Label(myWindow,font=("Algerian",100),background="black",foreground="cyan") lbl.pack() #calling time function time() #Calling function to Run Application mainloop()
0 Comments