Python Forum
[Tkinter] messagebox is not being executed please help
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] messagebox is not being executed please help
#1
Hello
I am trying to create my first Alarm Clock but I've stuck. I've simply created Tkinter window with a clock and some entry boxes and button to set the alarm time. Now:
1. The clock is working and its type is a string
2. Entry boxes are taking entered values and (after the "Set Time" button clicked) they are being shown in the grey label also as a string type.
3. I've made another def alarm(): to define that if the clock string is in the alarm time string then I want to message box to appear but for some reason, I have no errors and message box doesn't appear

can you please review my code and point me why showinfo() message box is no being executed.

import tkinter as tk
import time
import datetime
from tkinter.messagebox import *


def set_time():
    hour = entry_hour.get()
    minutes = entry_minutes.get()
    seconds = entry_seconds.get()
    time_set_label["text"] = hour.zfill(
        2) + ":" + minutes.zfill(2) + ":" + seconds.zfill(2)


window = tk.Tk()
window.title('Alarm Clock')
window.geometry('500x140')
window.resizable(width=False, height=False)

clock_label = tk.Label(master=window, background="gray",
                       font=("Arial", 40), width=10, height=1)
clock_label.place(x=100, y=0)

entry_hour = tk.Entry(width=4)
entry_hour.insert(0, "Hr")
entry_hour.place(x=10, y=70)
entry_minutes = tk.Entry(width=4)
entry_minutes.insert(0, "Min")
entry_minutes.place(x=50, y=70)
entry_seconds = tk.Entry(width=4)
entry_seconds.insert(0, "Sec")
entry_seconds.place(x=90, y=70)

set_time_button = tk.Button(master=window, width=7, height=1,
                            text="Set Time", padx="-10", command=set_time)
set_time_button.place(x=35, y=90)

time_set_label = tk.Label(master=window, background="gray", font=(
    "Arial", 40), width=9, height=1)
time_set_label.place(x=120, y=70)


def alarm():
    if time_set_label["text"] in clock_label["text"]:
        showinfo("Alarm", "Alarm!")


def tick():
    clock_label["text"] = time.strftime("%H:%M:%S")
    clock_label.after(200, tick)


tick()


window.mainloop()
Reply
#2
You need to test the alarm periodically. I think the alarm() code belongs in the tick() code. And change the test for if it is time for the alarm to go of or you will be surprised
Reply
#3
You never call alarm function
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] Sound from the tkinter.messagebox tedarencn 2 1,375 Jul-11-2020, 10:45 AM
Last Post: steve_shambles
  [Tkinter] Messagebox with playsound khandelwalbhanu 6 847 May-16-2020, 11:40 AM
Last Post: chesschaser
  [Tkinter] passing data to messagebox kmusawi 0 684 Feb-18-2019, 01:51 AM
Last Post: kmusawi
  Adding timer on the Messagebox aniyanetworks 6 4,640 Feb-13-2019, 07:48 PM
Last Post: aniyanetworks
  [Tkinter] Button widget gets stuck from using tkinter.messagebox? Nwb 2 1,838 Jun-20-2018, 02:21 PM
Last Post: Nwb
  [Tkinter] Window unresponsive when executed. fawazcode 2 1,786 Sep-11-2017, 12:29 AM
Last Post: Larz60+
  [WxPython] Which def is executed? merlem 10 4,347 Feb-10-2017, 11:28 AM
Last Post: Yoriz
  [xbmc] How to block the code from executed twice under the loop chris0147 29 12,628 Oct-26-2016, 05:34 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

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