Casey Bralla via plug on 23 Jan 2024 15:21:01 -0800 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
[PLUG] Raspbian S*cks! |
#!/usr/bin/python3 # -*- coding: utf-8 -*- # # DigitalClock.py # # # Display an nice looking digital clock for general use # Can be used as a dedicated clock on old Monitors with Raspberry Pi # # Version = "1.22" Author = "J R Casey Bralla" Program = "DigitalClock.py" # Import some standard python modules import os # misc operating system calls. import sys # More misc operating system calls import datetime # Time & Date functions import tkinter # Screen manipulation and information from tkinter import ttk # TK-Intger themed widgets # Get the command line arguments CommandLineArguments = sys.argv[1:] # print ( CommandLineArguments ) # CommandLineArgument = "" if len( CommandLineArguments ) > 0: # # show help # # print ( ) print ( "Program" + Program ) print ( ) print ( "Version " + Version ) print ( " by " + Author ) print ( ) print ( "Nice Digital Clock for general display" ) print ( ) print ( 'Usage: "' + Program + ' --help or -h for help"' ) print ( ) print ( ) print ( ) sys.exit(0) # # Set some Variables # # CompositeVideo = "No" # Composite Video cannot determine the max widow size properly Screen_Color = "Black" # Background color for the screen Time_Color = "White" # Font Color for Time DayOfWeek_Color = "Yellow" # Font Color for Day of Week LongDate_Color = "Yellow" # Font Color for Long Date ISODate_Color = "Yellow" # Font Color for ISO Date ### Create the Window ### ### Create the Window ### ### Create the Window ### # # # MainWindow = tkinter.Tk() MainWindow.title( "NerdWorld Digital Clock" ) MainWindow.configure( bg="black" ) MainWindow.attributes( '-topmost', True ) # Always on top # Window dimensions are the maximum window size if CompositeVideo == "Yes": # WindowWidth = 720 WindowHeight = 480 # else: # WindowWidth = MainWindow.winfo_screenwidth() WindowHeight = MainWindow.winfo_screenheight() # # MainWindow.geometry( str(WindowWidth) + "x" + str(WindowHeight) ) # TimeSize = int( WindowWidth * (72/96) / 8 ) DayOfWeekSize = int( WindowWidth * (72/96) / 13 ) LongDateSize = int( WindowWidth * (72/96) / 12 ) ISODateSize = int( WindowWidth * (72/96) / 20 ) # ### Function which acts as the main loop that updats the Time & Date ### ### Function which acts as the main loop that updats the Time & Date ### ### Function which acts as the main loop that updats the Time & Date ### # # # def UpdateClockDisplay(): # # ### Get the Time and Date and format it ### # TimeNow = datetime.datetime.now() # Time = TimeNow.strftime( "%-I:%M:%S %p" ) DayOfWeek = TimeNow.strftime( "%A" ) LongDate = TimeNow.strftime( "%B %-d, %Y" ) ISODate = TimeNow.strftime( "%Y-%m-%d" ) # # # Set the font sizes based on the window size # TimeSize = 24 # Font Size for Time DayOfWeekSize = 18 # Font Size for Day of Week LongDateSize = 18 # Font Size for Long Date ISODateSize = 12 # Font Size for ISO Date # if CompositeVideo != "Yes": # Use the maximum if no window manager # WindowWidth = MainWindow.winfo_width() # Variable based on window size # else: # WindowWidth = 720 # Fixed width for composite video # # # print (WindowWidth) # # TimeSize = int( WindowWidth * (72/96) / 8 ) DayOfWeekSize = int( WindowWidth * (72/96) / 13 ) LongDateSize = int( WindowWidth * (72/96) / 12 ) ISODateSize = int( WindowWidth * (72/96) / 20 ) # # # # ### Display the Time ### ### Display the Time ### ### Display the Time ### # TimeLabel.config( text=Time, font=("Helvetica", TimeSize) ) DayOfWeekLabel.config( text=DayOfWeek, font=("Helvetica", DayOfWeekSize) ) LongDateLabel.config( text=LongDate, font=("Helvetica", LongDateSize) ) ISODateLabel.config( text=ISODate, font=("Helvetica", ISODateSize) ) BlankLabel.config( text=" " ) # # # Force an update after waiting milliseconds # TimeLabel.after(250, UpdateClockDisplay) # Updates every quarter second. (No more than .25 seconds error) # # # ### Define the labels ### ### Define the labels ### ### Define the labels ### # # # TimeLabel = ttk.Label( MainWindow, text="*", foreground=Time_Color, background="black" ) # DayOfWeekLabel = ttk.Label( MainWindow, text="*", foreground=DayOfWeek_Color, background="black" ) # LongDateLabel = ttk.Label( MainWindow, text="*", foreground=LongDate_Color, background="black" ) # ISODateLabel = ttk.Label( MainWindow, text="*", foreground=ISODate_Color, background="black" ) # BlankLabel = ttk.Label( MainWindow, text="*", font=("Helvetica", 10), foreground="white", background="black" ) ### Pack the labels onto the window # # TimeLabel.pack( side=tkinter.TOP, expand=True ) DayOfWeekLabel.pack(side=tkinter.TOP, ipady = 5, expand=False ) LongDateLabel.pack( side=tkinter.TOP, ipady = 5, expand=False ) ISODateLabel.pack( side=tkinter.TOP, ipady = 5, expand=False ) BlankLabel.pack( side=tkinter.TOP, ipady = 5, expand=True ) # # # ### Run the function to update the labels ### # # UpdateClockDisplay() ### Obligatory TKInter routine to keep window open MainWindow.mainloop()
___________________________________________________________________________ Philadelphia Linux Users Group -- http://www.phillylinux.org Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce General Discussion -- http://lists.phillylinux.org/mailman/listinfo/plug