Nov-10-2019, 02:21 AM
(This post was last modified: Nov-10-2019, 02:21 AM by tickandatock_.)
Hello,
I am working on creating an alarm clock GUI using Tkinter as a project. I am planning to run it on a Raspberry Pi 3 B+, using Mu as it had came
preinstalled, Python 3 and Raspbian.
I'm trying to print the current time, a message saying "Good Morning" or "Good Afternoon" etc. depending on the time of day, and as well as the current date (I have not started in creating this yet).
I'm running into a problem where the program doesn't open up when I run it.
It was able to show the current time just fine before, but when I added the code to make it say "Good Morning" it doesn't load. I tried printing the time separately but it doesn't work anymore, either.
Can someone help me figure this out?
I though that the problem was because it was refreshing the message too many times, but it made no difference when I imported time and made the program wait a couple of seconds.
Also, if you have any suggestions on how to make something better or add the date, please feel free to reply!
Thanks!
I am working on creating an alarm clock GUI using Tkinter as a project. I am planning to run it on a Raspberry Pi 3 B+, using Mu as it had came
preinstalled, Python 3 and Raspbian.
I'm trying to print the current time, a message saying "Good Morning" or "Good Afternoon" etc. depending on the time of day, and as well as the current date (I have not started in creating this yet).
I'm running into a problem where the program doesn't open up when I run it.
It was able to show the current time just fine before, but when I added the code to make it say "Good Morning" it doesn't load. I tried printing the time separately but it doesn't work anymore, either.
Can someone help me figure this out?
I though that the problem was because it was refreshing the message too many times, but it made no difference when I imported time and made the program wait a couple of seconds.
Also, if you have any suggestions on how to make something better or add the date, please feel free to reply!
Thanks!
# GUISCRIPT.py # IMPORTS from tkinter import * import tkinter as tk import time import time as tm import threading import datetime # LOAD WINDOW gui_window = tk.Tk() gui_window.configure(background="black") gui_window.attributes("-fullscreen", True) # DISPLAY THE CURRENT TIME # RETRIEVE THE CURRENT TIME def display_time(): current_our = tm.strftime('%I:') our_label['text'] = current_our our_label.after(1000,display_time) current_minute = tm.strftime('%M') minute_label['text'] = current_minute minute_label.after(1000,display_time) current_am = tm.strftime(' %p') am_label['text'] = current_am am_label.after(1000,display_time) # DISPLAY THE CURRENT TIME our_label=tk.Label(gui_window,font='CodeDemoBold 300',bg='black',fg='white') our_label.grid(row=0,column=0) minute_label=tk.Label(gui_window,font='CodeDemoLight 300',bg='black',fg='white') minute_label.grid(row=0,column=1) am_label=tk.Label(gui_window,font='CodeDemoBold 300',bg='black',fg='white') am_label.grid(row=0,column=2) display_time() # DISPLAY THE GOOD MORNING MESSAGE (DEPENDENT ON THE TIME) # RETRIEVE MORNING TEXT def morningTextretrieve(): currentTime = datetime.datetime.now() currentTime.hour if 6 <= currentTime.hour <= 12: morningText = "Good Morning!" elif 13 <= currentTime.hour <= 18: morningText = "Good Afternoon!" elif 19 <= currentTime.hour <= 5: morningText = "Good Night!" time.sleep(10) i = 1 while i < 10: morningTextretrieve() time.sleep(10) morningtextLabel['text'] = morningText # DISPLAY THE GOOD MORNING MESSAGE morningtextLabel=tk.Label(gui_window,font='CodeDemoBold 300',bg='black',fg='white') morningtextLabel.grid(row=5,column=0) gui_window.mainloop()