Block
Block

Reputation: 179

Not responding in tkinter screen

Iam building a project tkinter. Here my Code

from tkinter import *
screen=Tk()
screen.geometry('500x300+400+200')
def play():
    from playsound import playsound
    playsound("music.mp3")
screen.title("Simple project")
btn=Button(screen,text='play',width=20,command=play).place(x=340,y=260)
screen.mainloop()

And when I click button "play" then tkinter screen is Not responding.

enter image description here

So how can I fix it.

Thank you

Upvotes: 0

Views: 139

Answers (1)

user15801675
user15801675

Reputation:

You can use threading module.

from tkinter import *
from threading import Thread

screen=Tk()
screen.geometry('500x300+400+200')
def play():
    from playsound import playsound
    playsound("music.mp3")

def start_play():
    t=Thread(target=play)
    t.daemon=True
    t.start()

screen.title("Simple project")
btn=Button(screen,text='play',width=20,command=start_play).place(x=340,y=260)
screen.mainloop()

Upvotes: 1

Related Questions