Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
tkinter clock
#1
Hello everyone,

I need help to make simple clock app which will change background color in choosen periods with duration for few secc and after then transform back. I created simple clock with tkinter, which you can see bellow, but I have problem with conditions of the changing of background color. I will appreciate any idea. thanks

import sys
from tkinter import *
import time

def tick():
    time_string=time.strftime("%H:%M:%S")
    clock.config(text=time_string)
    clock.after(200,tick)
    
root=Tk()
clock=Label(root, font=("times", 100, "bold"), bg="red")
clock.grid(row=0, column=1)
tick()
root.mainloop()
Reply
#2
import sys, random
from tkinter import *
import time
.
colors = ( "red", "black", "blue" )

def tick():
    time_string=time.strftime("%H:%M:%S")
    clock.config(text=time_string)
    clock.after(1000,tick)
    clock["bg"] = colors[random.randint(0, len(colors)-1)]

root=Tk()
clock=Label(root, font=("times", 100, "bold"), bg="red")
clock.grid(row=0, column=1)
tick()
root.mainloop()
Reply
#3
Thank you very much!!! Just one more thing and I will be absolutely satisfied. Is possible to set exactly time when should clock change the color? For example 14:20:30 change color to red with duration 40 secc and repeat again after 15 min... Thank you very much!!!
Reply
#4
if time_string == "14:20:30":
        clock["bg"] = ...
Reply
#5
Thank you!!!!!
Reply
#6
15 min later:

#!/usr/bin/python3
import time

# time now
time_sec = time.time()
time_string = time.strftime("%H:%M:%S", time.localtime(time_sec))
print(time_string)

# time 15 min later
time_sec = time_sec + 15*60
time_string = time.strftime("%H:%M:%S", time.localtime(time_sec))
print(time_string)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python clock menator01 2 850 May-14-2020, 10:23 PM
Last Post: menator01
  [Tkinter] Alarm Clock GUI tickandatock_ 1 2,632 Nov-10-2019, 02:52 AM
Last Post: Larz60+
  Clock freezes - wx.python glib problem strongheart 3 2,532 Oct-10-2017, 03:36 AM
Last Post: strongheart

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020