Python Forum
TKINTER - Change font color for night or day
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
TKINTER - Change font color for night or day
#1
Hi Everyone,

I would like to know if it's possible, with TKinter, to change font color from 10am to 10pm and form 10pm to 10 am, for example, from 10am to 10pm, it's day, font is green .. from 10pm to 10am it's night, font is blue.. I know how to change color but this is with the time management that i don't see how to do..

Here is my code
from tkinter import *
from time import *


class DigitalClock:

    def __init__(self, window):
        self.time_init = ""
        self.label = Label(window, font = ("arial", "180", "bold"),
                           bg = "black", fg = "lime")
        self.label.pack(fill ="both", expand = 1)
        self.label.after(1000, self.timer)

    # ------------------------------------------------------------------------
    def timer(self):
        self.time2 = strftime("%H : %M\n%S")

        if self.time2 != self.time_init:
            self.time_init = self.time2
            self.label.config(text = self.time2)
            self.label.after(1000, self.timer)

# ============================================================================
if __name__ == "__main__":
    master = Tk()
    master.geometry("1024x600")
    master.title("Digital Clock")
    clock = DigitalClock(master)
    # -- Fullscreen Mode
    #master.attributes('-fullscreen', True)
    # -- Deactivate mouse cursor
    #master.config(cursor = "none")
    master.mainloop()
Thank you all :)
Reply


Messages In This Thread
TKINTER - Change font color for night or day - by Ayckinn - May-24-2020, 01:45 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyQt] [Solved]Change text color of one line in TextBrowser Extra 2 4,756 Aug-23-2022, 09:11 PM
Last Post: Extra
  [Tkinter] Tkinter don't change the image DQT 2 1,556 Jul-22-2022, 10:26 AM
Last Post: menator01
  Tkinter - How can I change the default Notebook border color? TurboC 5 14,629 May-23-2022, 03:44 PM
Last Post: bigmac
Question [Tkinter] Change Treeview column color? water 3 9,408 Mar-04-2022, 11:20 AM
Last Post: Larz60+
  Can't get tkinter button to change color based on changes in data dford 4 3,361 Feb-13-2022, 01:57 PM
Last Post: dford
  how to change font size barryjo 4 3,749 Jan-26-2022, 08:46 PM
Last Post: menator01
  [Tkinter] Trouble changing Font within tkinter frame title AnotherSam 1 4,006 Sep-30-2021, 05:57 PM
Last Post: menator01
  tkinter change the text of the checkbox zazas321 1 3,753 Sep-17-2021, 06:19 AM
Last Post: zazas321
Question [Tkinter] Can I set background color for each item in tkinter Combobox? water 1 5,055 Dec-10-2020, 07:48 PM
Last Post: Larz60+
  Tkinter menu font size -method to change tonycat 2 7,700 Oct-11-2020, 02:43 AM
Last Post: tonycat

Forum Jump:

User Panel Messages

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