1

My code for an alarm in tkinter won't open on double click. It runs in idle just fine and all my other tkinter programs open on double click too. What in the code is causing this?

from tkinter import * 
import datetime
import time
from time import strftime
import winsound

master = Tk()  
master.geometry('300x300') 
master.title('Alarm Time') 

label = Label(master, text = 'What time would you like to wake up?') 
label.pack() 

EnteredAlarm = Entry(master) 
EnteredAlarm.pack(ipady=8)

def callback():           
    Alarm = EnteredAlarm.get()                
    while True:
        Time = strftime('%H:%M') 


        if str(Time) == str(Alarm): 
            print('Wake up Mister West')
            winsound.PlaySound('Alarm.wav', winsound.SND_FILENAME)
            break


        else:
            print('Zzz...')
            time.sleep(5)




b = Button(master, text="OK", command=callback)   
b.pack()       

The code doesn't return any errors, all that happens is cmd opens for half a second then closes. Any help is appreciated, thanks in advance.

1
  • You call master.mainloop() right? Commented Dec 5, 2017 at 17:47

1 Answer 1

2

You need to add master.mainloop() at the end of your program, as the last logical line.

This forces the program to continually update everything.

Sign up to request clarification or add additional context in comments.

3 Comments

I cannot believe that was it, thanks mate. All my other programs work without this which is why I was confused.
@MaxStrange program can runs without mainloop() in IDLE because IDLE is created with tkinter and it runs mainloop() to work.
No problem @MaxStrange. If you could mark the answer as correct then that would be great.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.