'Multiprocessing makes closed tkinter gui pop up again
In my program I want a window to pop up first asking which files the user would like and then open the actual program. It works fine but when I try to activate the function in the other program the first one pops up and I have to close it for the actual function to start. I think this is due to the multiprocessing but i am not sure.
import tkinter as tk
import multiprocessing
from playsound import playsound
from tkinter import *
from tkinter.filedialog import askopenfilename
global Pianobool
Pianobool = False
def Piano():
playsound(r'F:\Backup\Game.Develop\In.Develop\numbe.py\STEMOPLAYER/Piano.mp3')
p = multiprocessing.Process(target=Piano)
def awodijhaw():
root = tk.Tk()
def PlayPiano():
global Pianobool
if Pianobool:
global p
p.terminate()
Pianobool = False
print('Paused')
p = multiprocessing.Process(target=Piano)
elif not Pianobool:
p.start()
print('Started')
Pianobool = True
p.join
root.title('STEMOPLAYER')
root.geometry("700x700")
root.config(bg='#212124')
Pianobutton = Button(root,bg='#007aff',fg='white',text='Piano',height=25, width=25, command=(PlayPiano))
Pianobutton.place(x=550,y=250)
title = Label(root, text="STEMOPLAYER",bg='#212124', fg='white')
title.config(font=("Courier", 80, ))
title.place(x=0, y=100)
root.mainloop()
root = tk.Tk()
root.title('STEMOPLAYER')
root.geometry("650x350")
root.config(bg='#212124')
#BOOLS
Pianobol = False
def choosePianos():
Tk().withdraw()
Pianofilename = askopenfilename()
stringpiano = str(Pianofilename)
pianochoice = Label(root,bg='#007aff',fg='white', text=stringpiano)
pianochoice.place(x=30,y=50)
print(stringpiano)
Pianobol = True
def confirm():
popupo = tk.messagebox.askquestion ('Are you sure','Are you sure you want to continue to STEMOPLAYER',icon = 'info')
if popupo == 'yes':
root.destroy()
awodijhaw()
choosePiano = Button(root,bg='#007aff',fg='white', text="choosePiano",command=(choosePianos))
choosePiano.place(x=30, y=30)
Confirmbutton = Button(root,bg='#007aff',fg='white', text='COnfirm', height=2, width=10, command=(confirm))
Confirmbutton.place(x=330, y= 300)
root.mainloop()
Here is the code the playsound mechanic works great on its own but fails when combined.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
