Python Clock Script

Forum Forums General Software Python Clock Script

  • This topic has 2 replies, 1 voice, and was last updated Jun 18-5:19 pm by Brian Masinick.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #84748
    Moderator
    Brian Masinick

      I’m starting again at the site https://www.codeunderscored.com/make-digital-clock-python/ to copy and investigate a clock script written in Python.

      --
      Brian Masinick

      #84749
      Moderator
      Brian Masinick
        Helpful
        Up
        0
        ::

        I found multiple clock projects that may help a novice python program writer.

        I was able to grab 3 examples, change the % variable to display time the way I prefer it and they all work.

        --
        Brian Masinick

        #84813
        Moderator
        Brian Masinick
          Helpful
          Up
          0
          ::
          # PyClock.py from https://www.codeunderscored.com/make-digital-clock-python/
          # Copied by Brian Masinick on Saturday, June 18, 2022
          
          # importing the entire tkinter module
          from tkinter import *
          from tkinter.ttk import *
          
          # to retrieve the system's time, you need to import the strftime function
          from time import strftime
          
          # creation of the tkinter window
          main = Tk()
          main.title('The digital clock in Python')
          
          # This function displays the current time on the label defined herein
          def displayTime():
          	string = strftime('%r')
          	clock_label.config(text = string)
          	clock_label.after(1000, displayTime)
          
          # creating an attractive look:  needs styling the label widget
          clock_label = Label(main, font = ('calibri', 42, 'bold'),
          			background = 'purple',
          			foreground = 'white')
          
          # defining how to place the digital clock at the centre tkinter's window
          clock_label.pack(anchor = 'center')
          displayTime()
          
          mainloop()

          --
          Brian Masinick

        Viewing 3 posts - 1 through 3 (of 3 total)
        • You must be logged in to reply to this topic.