Skip to content

Commit

Permalink
Merge pull request #216 from ananyag309/master
Browse files Browse the repository at this point in the history
Add Digital Clock using Python and Tkinter
  • Loading branch information
UTSAVS26 authored Oct 7, 2024
2 parents eae05db + f8c6a31 commit a0b171f
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
Binary file added Beginner_Projects/Digital Clock/Digital Clock.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions Beginner_Projects/Digital Clock/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Digital Clock using Python and Tkinter
This script create a digital clock as per the system's current time.

## Library Used
* tkinter
* time

### To install required external modules
* Run `pip install tkinter`

### How to run the script
- Execute `python3 digital_clock.py`

### Screenshot/GIF showing the sample use of the script

![Digital Clock Output](Beginner_Projects/Digital Clock/Digital Clock.PNG)
56 changes: 56 additions & 0 deletions Beginner_Projects/Digital Clock/digital_clock.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import tkinter as tk
from time import strftime


def light_theme():
frame = tk.Frame(root, bg="white")
frame.place(relx=0.1, rely=0.1, relwidth=0.8, relheight=0.8)
lbl_1 = tk.Label(frame, font=('calibri', 40, 'bold'),
background='White', foreground='black')
lbl_1.pack(anchor="s")

def time():
string = strftime('%I:%M:%S %p')
lbl_1.config(text=string)
lbl_1.after(1000, time)
time()


def dark_theme():
frame = tk.Frame(root, bg="#22478a")
frame.place(relx=0.1, rely=0.1, relwidth=0.8, relheight=0.8)
lbl_2 = tk.Label(frame, font=('calibri', 40, 'bold'),
background='#22478a', foreground='black')
lbl_2.pack(anchor="s")

def time():
string = strftime('%I:%M:%S %p')
lbl_2.config(text=string)
lbl_2.after(1000, time)
time()


root = tk.Tk()
root.title("Digital-Clock")
canvas = tk.Canvas(root, height=140, width=400)
canvas.pack()

frame = tk.Frame(root, bg='#22478a')
frame.place(relx=0.1, rely=0.1, relwidth=0.8, relheight=0.8)
lbl = tk.Label(frame, font=('calibri', 40, 'bold'),
background='#22478a', foreground='black')
lbl.pack(anchor="s")

def time():
string = strftime('%I:%M:%S %p')
lbl.config(text=string)
lbl.after(1000, time)
time()

menubar = tk.Menu(root)
theme_menu = tk.Menu(menubar, tearoff=0)
theme_menu.add_command(label="Light", command=light_theme)
theme_menu.add_command(label="Dark", command=dark_theme)
menubar.add_cascade(label="Theme", menu=theme_menu)
root.config(menu=menubar)
root.mainloop()

0 comments on commit a0b171f

Please sign in to comment.