pip install pygame
Digital-Clock-with-Ticking-Sound
Digital Clock with Ticking Sound in Python
Requirements in Python3
- tkinter
- sudo apt-get update
- sudo apt-get install python3-tk
- pygame
- pip install pygame
app.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
from tkinter import * import pygame #for tick tick sound in clock from time import strftime,sleep root=Tk() root.title('Digital Clock') root.geometry("300x120") pygame.mixer.pre_init(frequency=44100, size=-16, channels=1, buffer=512) pygame.mixer.init() def time(): string = strftime(' %I:%M:%S %p ') lbl.config(text = string) lbl.after(1000, time) def clocktick(): #playing Ticking Sound pygame.mixer.music.load("ClockTick.mp3") pygame.mixer.music.set_volume(0.5) #range b/w 0 to 1 pygame.mixer.music.play(-1) def clocktickPause(): #Pausing Ticking Sound pygame.mixer.music.pause() lbl = Label(root, font = ('calibri', 40, 'bold'), background = 'grey', foreground = 'white') lbl.grid(row=1,column=0,columnspan=2) b2=Button(root,text='Play',width=43,command=clocktick,background='green') b2.grid(row=4,column=0) b3=Button(root,text='Pause',width=43,command=clocktickPause,background='red') b3.grid(row=5,column=0) time() root.after_idle(clocktick) root.mainloop() |
DOWNLOAD FULL SOURCE CODE