Advertisement
Jump_off_a_cliff

Perfect Clock GUI // Made with Github Copilot

May 28th, 2022
721
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # import the necessary modules
  2. import time
  3. import datetime
  4. import tkinter as tk
  5.  
  6. # create a class for the clock
  7.  
  8.  
  9. class Clock(tk.Frame):
  10.     # create the constructor
  11.     def __init__(self, parent, *args, **kwargs):
  12.         # call the constructor of the parent class
  13.         tk.Frame.__init__(self, parent, bg='black')
  14.         # create the label
  15.         self.timeLabel = tk.Label(self, font=(
  16.             'times', 50, 'bold'), bg='black', fg='white')
  17.         # pack the label
  18.         self.timeLabel.pack(fill='both', expand=1)
  19.         # call the update clock function
  20.         self.update_clock()
  21.  
  22.     # create the update clock function
  23.     def update_clock(self):
  24.         # get the current time
  25.         time = str(datetime.datetime.now().strftime('%H:%M:%S'))
  26.         # set the time label
  27.         self.timeLabel.config(text=time)
  28.         # call the update clock function again after 1 second
  29.         self.timeLabel.after(1000, self.update_clock)
  30.         # pack everything necessary
  31.         self.pack()
  32.  
  33.     # create the main function
  34.  
  35.     def main(self):
  36.         # start the main loop
  37.         self.mainloop()
  38.  
  39.  
  40. # create the clock object
  41. clock = Clock(tk.Tk())
  42. # call the main function
  43. clock.main()
  44. # end of file
  45. #!/usr/bin/env python3
  46. # Path: Tutorial.py
  47. # create a clock gui
  48.  
Advertisement
RAW Paste Data Copied
Advertisement