Question

Could someone please explain why this bit of code pauses until I delete the popup Frame?

How do I get the program to leave the message on the pop up frame and continue the program!

import winsound
import Tkinter

MessFrame = Tkinter.Tk()
MessFrame.geometry('800x400+200+200')
MessFrame.title('Main Frame')
Framelabel = Tkinter.Label(MessFrame, text='Text Here', fg= 'red')
Framelabel.place(x=10,y=10)
MessFrame.mainloop()

winsound.Beep(500,1000)

Edit 1 - I was hoping it would display the "text" - leave the Frame / text displayed and then "beep" The beep doesnt happen until the Frame is closed!

Was it helpful?

Solution

You can use threading or multiprocessing:

import winsound
import Tkinter
import threading

def create_frame():
    MessFrame = Tkinter.Tk()
    MessFrame.geometry('800x400+200+200')
    MessFrame.title('Main Frame')
    Framelabel = Tkinter.Label(MessFrame, text='Text Here', fg= 'red')
    Framelabel.place(x=10,y=10)
    MessFrame.mainloop()


t1 = threading.Thread(target=create_frame)
t1.start()

winsound.Beep(500,1000)

OTHER TIPS

import winsound
import Tkinter

MessFrame = Tkinter.Tk()
MessFrame.geometry('800x400+200+200')
MessFrame.title('Main Frame')
Framelabel = Tkinter.Label(MessFrame, text='Text Here', fg= 'red')
Framelabel.place(x=10,y=10)
winsound.Beep(500,1000) # put beep before mainloop()
MessFrame.mainloop()

Any lines after mainloop() will only be executed when you exit the mainloop by exiting the program.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top