Python Forum
[PyGUI] pygame button stuck(unable to do anything)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyGUI] pygame button stuck(unable to do anything)
#11
So, i did as you suggested.
####################################################################################################
thread_pool_executor = futures.ThreadPoolExecutor(max_workers=1)
####################################################################################################
def on_question1():
        pygame.init()
        pygame.mixer.init()
        pygame.mixer.music.load("google_pt.mp3")
        pygame.mixer.music.play(0)
        time.sleep(3)
        pygame.mixer.music.load("google_en.mp3")
        pygame.mixer.music.play(0)
        time.sleep(0)
  
        for x in range(1, 101):
            window.after(0, progress_var.set, x)
            time.sleep(0.05)
         
        window.after(0, progress_var.set, 0)                  
        webbrowser.open("www.google.com")
        window.after(0, bot.set, '')
####################################################################################################
def main():
    question = Utilizador.get()# - google website
    if question in user_1:
        bot.set(choice(bot_info2))
        Utilizador.set('')
        thread_pool_executor.submit(on_question1)
####################################################################################################
The progressbar works, and the website opens, but no sound is reproduced.
Reply
#12
Has the pygame sound code been tested independently and been proven to work?

Edit: I installed pygame and tried to play an mp3
import pygame
import time

file = 'Alone.mp3'

pygame.init()
pygame.mixer.init()
pygame.mixer.music.load(file)
pygame.mixer.music.play(0)
time.sleep(3)
There was no errors but the mp3 did not play.

I tried using https://pypi.org/project/playsound/ and it played the mp3 so i tried playing it a seperate thread and that worked too.
from playsound import playsound
from concurrent import futures

thread_pool_executor = futures.ThreadPoolExecutor(max_workers=1)

def playmp3(file):
    playsound(file)


file = 'Alone.mp3'
thread_pool_executor.submit(playmp3, file)
Reply
#13
(Apr-27-2019, 08:46 AM)Yoriz Wrote: Has the pygame sound code been tested independently and been proven to work?

Edit: I installed pygame and tried to play an mp3
import pygame
import time

file = 'Alone.mp3'

pygame.init()
pygame.mixer.init()
pygame.mixer.music.load(file)
pygame.mixer.music.play(0)
time.sleep(3)
There was no errors but the mp3 did not play.

I tried using https://pypi.org/project/playsound/ and it played the mp3 so i tried playing it a seperate thread and that worked too.
from playsound import playsound
from concurrent import futures

thread_pool_executor = futures.ThreadPoolExecutor(max_workers=1)

def playmp3(file):
    playsound(file)


file = 'Alone.mp3'
thread_pool_executor.submit(playmp3, file)

After a few changes, no freezing the main gui, perfect Yoriz. I put this code the way you said. Now it goes on a loop. Goes first joke, second joke, and repeats it over and over. Maybe i should only change where it says max workers, it looks like is something about it, not sure do.

def test():
        thread_pool_executor = futures.ThreadPoolExecutor(max_workers=1)

        def playmp3(file):
                playsound(file1)
                playsound(file2)
 
 
        file1 = 'piada1_pt.mp3'
        file2 = 'piada2_pt.mp3'
        thread_pool_executor.submit(playmp3, file1)
        thread_pool_executor.submit(playmp3, file2)
Reply
#14
In the code above you have
 def playmp3(file):
        playsound(file1)
        playsound(file2)
should be as shown in my code before
 def playmp3(file):
        playsound(file)
what you have done has made it that each time playmp3 is called it will play file1 followed by file2 regardless of what file name is passed to it.
Don't change max_workers from 1, if you do it will play as mp3 at the same time as you set the value to, rather then wait till one is finished before playing the next.
Reply
#15
(Apr-27-2019, 04:31 PM)Yoriz Wrote: In the code above you have
 def playmp3(file): playsound(file1) playsound(file2) 
should be as shown in my code before
 def playmp3(file): playsound(file) 
what you have done has made it that each time playmp3 is called it will play file1 followed by file2 regardless of what file name is passed to it. Don't change max_workers from 1, if you do it will play as mp3 at the same time as you set the value to, rather then wait till one is finished before playing the next.

Well, since you solved my problem, i just put all the jokes into one mp3 file, i was going around and around, how to play the other jokes, so it is done. Many thanks yoriz, right now i'm about to be changing home, so the project isn't my first priority. But when i will be able to continue, i will put your name in my project (like a notice, "the main helper", something cool), if you don't mind.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Tkinter:Unable to bind and unbind function with a button shallanq 2 5,029 Mar-28-2020, 02:05 AM
Last Post: joe_momma
  [PySimpleGui] How to alter mouse click button of a standard submit button? skyerosebud 3 5,009 Jul-21-2019, 06:02 PM
Last Post: FullOfHelp
  Unable to return value from callback function of a button in Python Tkinter nilaybnrj 4 20,788 Aug-05-2018, 11:01 PM
Last Post: woooee
  [Tkinter] Button widget gets stuck from using tkinter.messagebox? Nwb 2 3,894 Jun-20-2018, 02:21 PM
Last Post: Nwb

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020