Python Forum
[Tkinter] Alarm Clock GUI
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Alarm Clock GUI
#1
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!


# 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()
Reply
#2
you may want to look at https://pypi.org/search/?q=alarmclock to get some new ideas.
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 clock Ondrej 5 2,585 Jun-06-2019, 02:09 PM
Last Post: heiner55
  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