I've adapted this countdown clock program from another member and it works except I want to make the text color change when the countdown hits 30 & 15 seconds. But it won't change the color. I have tried numerous ways, the last two of which (I commented out since neither works) in "colorupdate" (see lines 46 &47). I've searched the web for hours and still don't get it.
What am I (a python neophyte) doing wrong?
What am I (a python neophyte) doing wrong?
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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# Python3 import tkinter as tk import sys import time # Get variables # Timer_length = sys.argv[ 1 ] Timer_length = int (Timer_length) Xsize = sys.argv[ 2 ] Ysize = sys.argv[ 3 ] Xoffset = sys.argv[ 4 ] Yoffset = sys.argv[ 5 ] def count_down(): global Number_Color for t in range (Timer_length, - 1 , - 1 ): if (t is 30 ): colourUpdate( 'yellow' ) print ( 'Updated color' ) fg = Number_Color.get() print (t,fg) elif (t is 15 ): colourUpdate( 'red' ) # format as 2 digit integers, fills with zero to the left # divmod() gives minutes, seconds sf = "{:02d}:{:02d}" . format ( * divmod (t, 60 )) #print(sf) # test time_str. set (sf) root.update() # delay one second time.sleep( 1 ) # create root/main window root = tk.Tk() Number_Color = tk.StringVar() Number_Color. set ( 'blue' ) print (Number_Color.get()) def colourUpdate(color): Number_Color. set (color) fgx = Number_Color.get() print ( 'color: ' ,fgx) #root.configure(fg=Number_Color.get()) #root.update() root.overrideredirect( 1 ) # Set geometry size and location of Picture root.geometry( '%sx%s+%s+%s' % (Xsize, Ysize, Xoffset, Yoffset)) time_str = tk.StringVar() # create the time display label, give it a large font # label auto-adjusts to the font label_font = ( 'helvetica' , 40 ) tk.Label(root, textvariable = time_str, font = label_font, bg = 'white' , fg = Number_Color.get(), relief = 'raised' , bd = 3 ).pack(fill = 'x' , padx = 5 , pady = 5 ) count_down() # start the GUI event loop root.mainloop() |