Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # import the necessary modules
- import time
- import datetime
- import tkinter as tk
- # create a class for the clock
- class Clock(tk.Frame):
- # create the constructor
- def __init__(self, parent, *args, **kwargs):
- # call the constructor of the parent class
- tk.Frame.__init__(self, parent, bg='black')
- # create the label
- self.timeLabel = tk.Label(self, font=(
- 'times', 50, 'bold'), bg='black', fg='white')
- # pack the label
- self.timeLabel.pack(fill='both', expand=1)
- # call the update clock function
- self.update_clock()
- # create the update clock function
- def update_clock(self):
- # get the current time
- time = str(datetime.datetime.now().strftime('%H:%M:%S'))
- # set the time label
- self.timeLabel.config(text=time)
- # call the update clock function again after 1 second
- self.timeLabel.after(1000, self.update_clock)
- # pack everything necessary
- self.pack()
- # create the main function
- def main(self):
- # start the main loop
- self.mainloop()
- # create the clock object
- clock = Clock(tk.Tk())
- # call the main function
- clock.main()
- # end of file
- #!/usr/bin/env python3
- # Path: Tutorial.py
- # create a clock gui
Advertisement
RAW Paste Data
Copied
Advertisement