[Python] Tkinter threading with music

Discussão em 'Python' iniciado por Stack, Junho 3, 2025.

  1. Stack

    Stack Membro Participativo

    I have added a music button to my Tkinter GUI, when I press it, it plays music but the other aspects wont work such as clicking other buttons and moving the window, I have tried threading but still no advancements

    My Code:

    from playsound import playsound
    import tkinter as tk
    from tkinter import PhotoImage
    import threading

    def Menu():
    root = tk.Tk()
    root.title("Menu")
    root.geometry('400x400')
    root.configure(bg='blue')
    button = tk.Button(root, text="Blackjack", command=blackjack)
    button.pack()
    button.place(x=100, y=100)
    button1 = tk.Button(root, text="Roulette")
    button1.pack()
    button1.place(x=170, y=100)
    button2 = tk.Button(root, text="Quit", command=quit)
    button2.pack()
    button2.place(x=240, y=100)
    root.mainloop()

    def on_button_click():
    playsound('C:/Users/13AlexCoates/Untitled song (1).mp3')

    def thread():
    t1 = threading.Thread(target=blackjack)
    t1.run()
    t1.join()
    t2 = threading.Thread(target=on_button_click)
    t2.start()
    t2.join()

    def blackjack():
    root = tk.Tk()
    root.title("Blackjack")
    button3 = tk.Button(root, text='Music', command=on_button_click)
    button4 = tk.Button(root, text='Quit', command=Menu)
    bgcolour = input('What colour would you like the background to be?\n')
    button = tk.Button(root, text="Hit!")
    button1 = tk.Button(root, text="Double Down!")
    button2 = tk.Button(root, text="Stand!")
    button.pack()
    button1.pack()
    button2.pack()
    button3.pack()
    button4.pack()
    root.configure(bg=bgcolour)
    root.geometry("700x450")
    button.place(x=240, y=400)
    button1.place(x=315, y=400)
    button2.place(x=440, y=400)
    button3.place(x=1, y=1)
    button4.place(x=665, y=1)



    The threading aspect is not working and any help would be appreciated

    Continue reading...

Compartilhe esta Página