What kind of clock are you looking for. A line of text? An actual analog clock graphic?
i am new to python and wondering how to create a code for a clock for python
What kind of clock are you looking for. A line of text? An actual analog clock graphic?
You should probably just use an existing library, no need to reinvent the wheel!
Write out your algorithm in plain text on a notebook. Then Google how to convert each step to Python.
This is literally what goes on. Over time you'll memorize more and more of each language you're using, but it's pointless to sit down and learn a programming language when you can't even write algorithms.
Use stackoverflow it helps a lot as you have many users who have the same issues as you do usually.
a quick gui clock
to speak easy, we are using a linux distro
# install tkinter using terminal
sudo apt install python-tk
# make a text file and copy the text below, title file clock.py
# run file in terminal using: python clock.py
# import library
import time
import datetime
# sudo apt install python-tk
try:
from tkinter import *
except ImportError:
from Tkinter import *
# GUI root screen
root = Tk()
root.title('a clock')
root.geometry('250x25+0+0')
# get the clock time
def getClock():
start = time.time()
clock = datetime.datetime.fromtimestamp(start).strftime('% H:%M:%S')
label1 = Label(root, text=clock, font=("arial", 10,"bold"), fg="black").place(x=90,y=6)
root.after(1000, getClock)
root.after(1000, getClock)
root.mainloop()
Hi,
I have a python codes which will you to create clock. Get the PC formatted string using time string time('%H:%M:%S').Recursive string check five time per second.
Here is the coding part.
# use Tkinter to show a digital clock
# tested with Python24 vegaseat 10sep2006
from Tkinter import *
import time
root = Tk()
time1 = ''
clock = Label(root, font=('times', 20, 'bold'), bg='green')
clock.pack(fill=BOTH, expand=1)
def tick():
global time1
# get the current local time from the PC
time2 = time.strftime('%H:%M:%S')
# if time string has changed, update it
if time2 != time1:
time1 = time2
clock.config(text=time2)
# calls itself every 200 milliseconds
# to update the time display as needed
# could use >200 ms, but display gets jerky
clock.after(200, tick)
tick()
root.mainloop( )
Thanks...