Python Forum

Full Version: pygame button stuck(unable to do anything)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
from random import choice
import webbrowser
from tkinter import ttk
from tkinter import *
import tkinter
import time
from tkinter import messagebox
import pygame
import os
import sys

#########################Organização da janela tkinter#################################
root = Tk()
filename = PhotoImage(file = "C:/Bot/background.png")
background_label = Label(root, image=filename)
background_label.place(x=0, y=0, relwidth=1, relheight=1)
root_height = 350
root_width = 520
screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()
x_cordinate = int((screen_width/2) - (root_width/2))
y_cordinate = int((screen_height/2) - (root_height/2))
root.geometry("{}x{}+{}+{}".format(root_width, root_height, x_cordinate, y_cordinate))
#################################################################################################


###############################################################################################################
user_1 = ["google", "GOOGLE", "Google"]
############################
user_2 = ["facebook", "FACEBOOK", "Facebook"]
############################
user_3 = ["badoo", "BADOO", "Badoo"]
############################
user_4 = ["buzznet", "BUZZNET", "Buzznet"]
###########################
user_5 = ["care2", "CARE2", "Care2"]
############################
user_6 = ["cafemom", "CAFEMOM", "Cafemom"]
############################
user_7 = ["cellufun", "CELLUFUN", "Cellufun"]
############################
user_8 = ["classmates", "CLASSMATES", "Classmates"]
############################
user_9 = ["deviantart", "DEVIANTART", "Deviantart"]
###########################
user_10 = ["flixster", "FLIXSTER", "Flixster"]
###########################
user_11 = ["flickr", "FLICKR", "Flickr"]
###########################
user_12 = ["foursquare", "FOURSQUARE", "Foursquare"]
###########################
user_13 = ["funnyordie", "FUNNYORDIE", "Funnyordie"]
###########################
user_14 = ["gaiaonline", "GAIAONLINE", "Gaiaonline"]
###########################
user_15 = ["google+", "GOOGLE+", "Google+", "googleplus", "GOOGLEPLUS", "Googleplus"]
###########################
user_16 = ["instagram", "INSTAGRAM", "Instagram"]
###########################
user_17 = ["kiwibox", "KIWIBOX", "Kiwibox"]
###########################
user_18 = ["line", "LINE", "Line"]
###########################
user_19 = ["linkedin", "LINKEDIN", "Linkedin"]
###########################
user_20 = ["livejournal", "LIVEJOURNAL", "Livejournal"]
###########################
error = ["NÃO RECONHEÇO ESSA OPCAO - DON'T RECOGNIZE THAT OPTION"]
###########################
user_bad = []

###########################
user_piadas = ["piadas", "PIADAS", "Piadas", "rir", "RIR", "Rir", "comédia", "COMÉDIA", "Comédia", "comedia", "COMEDIA", "Comedia", "anedotas", "ANEDOTAS", "Anedotas"]
bot_info = ["AGUARDE ENQUANTO AS PIADAS TERMINAM", "O PROGRAMA FICARÁ BLOQUEADO ATÉ AS PIADAS TERMINAREM"]
###########################
user_jokes = ["laugh", "LAUGH", "Laugh", "jokes", "JOKES", "Jokes", "comedy", "COMEDY", "Comedy"]

####################################################################################################
Utilizador = StringVar()                          
bot = StringVar()
####################################################################################################

###################################################################################################
root.title("                                                              NeneBot v1.0 (alfa)")
Label(root, text=" Utilizador\nUSER ").place(x=20, y=10, width=60)
Entry(root, textvariable=Utilizador).place(x=100, y=15, width=400)
Label(root, text=" Bot ").place(x=20, y=60, width=70)                
Entry(root, textvariable=bot, state=DISABLED).place(x=100, y=60, width=400)              
###################################################################################################

##################################################################################################
def main():
    question = Utilizador.get()# - google website
    if question in user_1:
        Utilizador.set('')
        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, 110):
                progress_var.set(x)
                time.sleep(0.05)
                root.update()
                progress_var.set(0)
                            
        webbrowser.open("www.google.com")


    elif question in user_2:
        Utilizador.set('')# - facebook website

        pygame.init()
        pygame.mixer.init()
        pygame.mixer.music.load("facebook_pt.mp3")
        pygame.mixer.music.play(0)
        time.sleep(3)
        pygame.mixer.music.load("facebook_en.mp3")
        pygame.mixer.music.play(0)
        time.sleep(0)

        for x in range(1, 110):
                progress_var.set(x)
                time.sleep(0.05)
                root.update()
                progress_var.set(0)
                            
        webbrowser.open("www.facebook.com")
        

    elif question in user_3:
        Utilizador.set('')# - badoo website

        pygame.init()
        pygame.mixer.init()
        pygame.mixer.music.load("badoo_pt.mp3")
        pygame.mixer.music.play(0)
        time.sleep(3)
        pygame.mixer.music.load("badoo_en.mp3")
        pygame.mixer.music.play(0)
        time.sleep(0)

        for x in range(1, 110):
                progress_var.set(x)
                time.sleep(0.05)
                root.update()
                progress_var.set(0)
                            
        webbrowser.open("https://badoo.com/")

    elif question in user_4:
        Utilizador.set('')# - buzznet website

        pygame.init()
        pygame.mixer.init()
        pygame.mixer.music.load("buzznet_pt.mp3")
        pygame.mixer.music.play(0)
        time.sleep(3)
        pygame.mixer.music.load("buzznet_en.mp3")
        pygame.mixer.music.play(0)
        time.sleep(0)

        for x in range(1, 110):
                progress_var.set(x)
                time.sleep(0.05)
                root.update()
                progress_var.set(0)
                            
        webbrowser.open("www.buzznet.com/")

    elif question in user_5:
        Utilizador.set('')# - care2 website

        pygame.init()
        pygame.mixer.init()
        pygame.mixer.music.load("care2_pt.mp3")
        pygame.mixer.music.play(0)
        time.sleep(3)
        pygame.mixer.music.load("care2_en.mp3")
        pygame.mixer.music.play(0)
        time.sleep(0)

        for x in range(1, 110):
                progress_var.set(x)
                time.sleep(0.05)
                root.update()
                progress_var.set(0)
                            
        webbrowser.open("https://www.care2.com/")

    elif question in user_6:
        Utilizador.set('')# - cafemom website

        pygame.init()
        pygame.mixer.init()
        pygame.mixer.music.load("cafemom_pt.mp3")
        pygame.mixer.music.play(0)
        time.sleep(3)
        pygame.mixer.music.load("cafemom_en.mp3")
        pygame.mixer.music.play(0)
        time.sleep(0)

        for x in range(1, 110):
                progress_var.set(x)
                time.sleep(0.05)
                root.update()
                progress_var.set(0)
                            
        webbrowser.open("https://www.cafemom.com/")

    elif question in user_7:
        Utilizador.set('')# - cellufun website

        pygame.init()
        pygame.mixer.init()
        pygame.mixer.music.load("cellufun_pt.mp3")
        pygame.mixer.music.play(0)
        time.sleep(3)
        pygame.mixer.music.load("cellufun_en.mp3")
        pygame.mixer.music.play(0)
        time.sleep(0)

        for x in range(1, 110):
                progress_var.set(x)
                time.sleep(0.05)
                root.update()
                progress_var.set(0)
                            
        webbrowser.open("https://www.cellufun.com/games.asp?v=5gbwc9KMt00")

    elif question in user_8:
        Utilizador.set('')# - classmates website

        pygame.init()
        pygame.mixer.init()
        pygame.mixer.music.load("classmates_pt.mp3")
        pygame.mixer.music.play(0)
        time.sleep(3)
        pygame.mixer.music.load("classmates_en.mp3")
        pygame.mixer.music.play(0)
        time.sleep(0)

        for x in range(1, 110):
                progress_var.set(x)
                time.sleep(0.05)
                root.update()
                progress_var.set(0)
                            
        webbrowser.open("https://www.classmates.com/")

    elif question in user_9:
        Utilizador.set('')# - deviantart website

        pygame.init()
        pygame.mixer.init()
        pygame.mixer.music.load("deviantart_pt.mp3")
        pygame.mixer.music.play(0)
        time.sleep(3)
        pygame.mixer.music.load("deviantart_en.mp3")
        pygame.mixer.music.play(0)
        time.sleep(0)

        for x in range(1, 110):
                progress_var.set(x)
                time.sleep(0.05)
                root.update()
                progress_var.set(0)
                            
        webbrowser.open("https://www.deviantart.com/")

I'm stuck here, when the user write in the input "Jokes", after that, press the button, the same one stays stuck(like locked) and the pygame will start playing all the jokes. But, want i need is the pygame will still work, but the button will be released and the user be able to do anything else on the program

 elif question in user_piadas:
        bot.set(choice(bot_info))# - piadas(comedia)
        
        pygame.init()
        pygame.mixer.init()
        pygame.mixer.music.load("piada1_pt.mp3")
        pygame.mixer.music.play(0)
        time.sleep(14)
        pygame.mixer.music.load("piada2_pt.mp3")
        pygame.mixer.music.play(0)
        time.sleep(12)
        pygame.mixer.music.load("piada3_pt.mp3")
        pygame.mixer.music.play(0)
        time.sleep(13)
        pygame.mixer.music.load("piada4_pt.mp3")
        pygame.mixer.music.play(0)
        time.sleep(12)

        

    else:
        Utilizador.set(choice(error))
        Utilizador.set('')

        pygame.init()
        pygame.mixer.init()
        pygame.mixer.music.load("erro_pt.mp3")
        pygame.mixer.music.play(0)
        time.sleep(3)
        pygame.mixer.music.load("error_en.mp3")
        pygame.mixer.music.play(0)
        time.sleep(3)
    pygame.mixer.quit()




progress_var = tkinter.IntVar()
pb = ttk.Progressbar(root, orient="horizontal", length=400, maximum=100, mode="determinate", var=progress_var)
pb.place(x=100, y=100)

Button(root, text="Pressionar Botão\nPress Button", bg='green yellow', command=main).place(x=250, y=150)


class Clock:
    def __init__(self):
        self.time1 = ''
        self.time2 = time.strftime('%H:%M:%S')
        self.mFrame = Frame()
        self.mFrame.place(x=20, y=100)

        self.watch = Label(self.mFrame, text=self.time2, font=('times',12,'bold'))
        self.watch.pack()

        self.changeLabel()

    def changeLabel(self): 
        self.time2 = time.strftime('%H:%M:%S')
        self.watch.configure(text=self.time2)
        self.mFrame.after(200, self.changeLabel)
        
##############################
obj1 = Clock()
root.resizable(False,False)
root.mainloop()

if __name__=="__main__":
    main()
Using time.sleep in gui code or anything that takes some time to run will block the event loop and freeze the updating of the gui widgets.
To not lock the gui code that would freeze the gui would have to be put into a separate thread.
(Apr-24-2019, 09:37 PM)Yoriz Wrote: [ -> ]Using time.sleep in gui code or anything that takes some time to run will block the event loop and freeze the updating of the gui widgets.
To not lock the gui code that would freeze the gui would have to be put into a separate thread.

May i ask your for a short example how can i implement it based on my code?
The user will input the word "jokes" and the player will tell the jokes and the user will still be able to use the main gui.

If possible, just a small tip with code(please), i will do the rest myself.
I made a tutorial showing how to not block the main loop by using a separate thread.
https://python-forum.io/Thread-Tkinter-H...ng-the-gui
Yoriz, i have read your post, but it is the same like reading chinese to me. Sorry. If you have time and patient to rewrite some of my code with the changes, i would love it. Many thanks anyway. Just reply saying if you can or cannot do it. Ty
He means instead of using time.sleep you need another solution. The link leads to a tutorial on how to do that. If you were talking about the tutorials being a whole other language. I don't know if this is the most efficient solution but I would use multi threading. Make a timer func and when time runs out return something or some sorts.
(Apr-26-2019, 05:41 PM)SheeppOSU Wrote: [ -> ]He means instead of using time.sleep you need another solution. The link leads to a tutorial on how to do that. If you were talking about the tutorials being a whole other language. I don't know if this is the most efficient solution but I would use multi threading. Make a timer func and when time runs out return something or some sorts.

I wasn't saying for you to write in another language, i'm portuguese, but i do understand every word you say. When i said that, i was meaning, no ideia what to put where. So, basically no ideia what to do. I saw the tutorial, but errors, errors, tried so many ways. This sucks, i'm so dummy :(
I didn't mean literally an actual whole other language. I just meant hard to understand, sorry
I manage to do this, but it still block the main gui. Because the audio has one minute of duration ore more, if i don't set the time sleep doesn't work, just plays the last one, if i set to 0, it doesn't finish the jokes, just goes for next one. I've put all of my code separated by #, so you could help me easily. Pray

from random import choice
import webbrowser
from tkinter import ttk
from tkinter import *
import tkinter as tk
import tkinter
import time
import pygame
import os
import sys
###############################################################################################################
window = tkinter.Tk()
window.title("NeneBot v1.0 (alfa)")
filename = PhotoImage(file = "C:/Bot/background.png")
background_label = Label(window, image=filename)
background_label.place(x=0, y=0, relwidth=1, relheight=1)
window_height = 200
window_width = 520
screen_width = window.winfo_screenwidth()
screen_height = window.winfo_screenheight()
x_cordinate = int((screen_width/2) - (window_width/2))
y_cordinate = int((screen_height/2) - (window_height/2))
window.geometry("{}x{}+{}+{}".format(window_width, window_height, x_cordinate, y_cordinate))
###############################################################################################################
user_1 = ["google", "GOOGLE", "Google"]
############################
user_2 = ["facebook", "FACEBOOK", "Facebook"]
############################
user_3 = ["badoo", "BADOO", "Badoo"]
############################
user_4 = ["buzznet", "BUZZNET", "Buzznet"]
###########################
user_5 = ["care2", "CARE2", "Care2"]
############################
user_6 = ["cafemom", "CAFEMOM", "Cafemom"]
############################
user_7 = ["cellufun", "CELLUFUN", "Cellufun"]
############################
user_8 = ["classmates", "CLASSMATES", "Classmates"]
############################
user_9 = ["deviantart", "DEVIANTART", "Deviantart"]
###########################
user_10 = ["flixster", "FLIXSTER", "Flixster"]
###########################
user_11 = ["flickr", "FLICKR", "Flickr"]
###########################
user_12 = ["foursquare", "FOURSQUARE", "Foursquare"]
###########################
user_13 = ["funnyordie", "FUNNYORDIE", "Funnyordie"]
###########################
user_14 = ["gaiaonline", "GAIAONLINE", "Gaiaonline"]
###########################
user_15 = ["google+", "GOOGLE+", "Google+", "googleplus", "GOOGLEPLUS", "Googleplus"]
###########################
user_16 = ["instagram", "INSTAGRAM", "Instagram"]
###########################
user_17 = ["kiwibox", "KIWIBOX", "Kiwibox"]
###########################
user_18 = ["line", "LINE", "Line"]
###########################
user_19 = ["linkedin", "LINKEDIN", "Linkedin"]
###########################
user_20 = ["livejournal", "LIVEJOURNAL", "Livejournal"]
###########################
error = ["NÃO RECONHEÇO ESSA OPCAO - DON'T RECOGNIZE THAT OPTION"]
###########################
user_bad = []
###########################
user_piadas = ["piadas", "PIADAS", "Piadas", "rir", "RIR", "Rir", "comédia", "COMÉDIA", "Comédia", "comedia", "COMEDIA", "Comedia", "anedotas", "ANEDOTAS", "Anedotas"]
bot_info = ["AGUARDE ENQUANTO AS PIADAS TERMINAM", "O PROGRAMA FICARÁ BLOQUEADO ATÉ AS PIADAS TERMINAREM"]
###########################
user_jokes = ["laugh", "LAUGH", "Laugh", "jokes", "JOKES", "Jokes", "comedy", "COMEDY", "Comedy"]
###########################
user_info = ["nenebot", "NENEBOT", "Nenebot", "Informações sobre a aplicação", "INFORMAÇÕES SOBRE A APLICAÇÃO", "Informações sobre a aplicação", "informações sobre o software",
             "INFORMAÇÕES SOBRE O SOFTWARE", "Informações sobre o software", "application information", "APPLICATION INFORMATION", "Application information", "software Information",
             "SOFTWARE INFORMATION", "Software information"]
bot_info2 = ["Aguarde um momento - Wait a moment"]
####################################################################################################
Utilizador = StringVar()                          
bot = StringVar()
####################################################################################################
Label(window, text=" Utilizador\nUSER ").place(x=20, y=10, width=60)
Entry(window, textvariable=Utilizador).place(x=100, y=15, width=400)
Label(window, text=" Bot ").place(x=20, y=60, width=70)                
Entry(window, textvariable=bot, state=DISABLED).place(x=100, y=60, width=400)
####################################################################################################
def main():
    question = Utilizador.get()# - google website
    if question in user_1:
        bot.set(choice(bot_info2))
        Utilizador.set('')
        
        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, 110):
                progress_var.set(x)
                time.sleep(0.05)
                window.update()
                progress_var.set(0)
                            
        webbrowser.open("www.google.com")
        bot.set('')
####################################################################################################
    elif question in user_2:
        bot.set(choice(bot_info2))
        Utilizador.set('')# - facebook website

        pygame.init()
        pygame.mixer.init()
        pygame.mixer.music.load("facebook_pt.mp3")
        pygame.mixer.music.play(0)
        time.sleep(3)
        pygame.mixer.music.load("facebook_en.mp3")
        pygame.mixer.music.play(0)
        time.sleep(0)

        for x in range(1, 110):
                progress_var.set(x)
                time.sleep(0.05)
                window.update()
                progress_var.set(0)
                            
        webbrowser.open("www.facebook.com")
        bot.set('')
####################################################################################################
    elif question in user_3:
        bot.set(choice(bot_info2))
        Utilizador.set('')# - badoo website

        pygame.init()
        pygame.mixer.init()
        pygame.mixer.music.load("badoo_pt.mp3")
        pygame.mixer.music.play(0)
        time.sleep(3)
        pygame.mixer.music.load("badoo_en.mp3")
        pygame.mixer.music.play(0)
        time.sleep(0)

        for x in range(1, 110):
                progress_var.set(x)
                time.sleep(0.05)
                window.update()
                progress_var.set(0)
                            
        webbrowser.open("https://badoo.com/")
        bot.set('')
####################################################################################################
    elif question in user_4:
        bot.set(choice(bot_info2))
        Utilizador.set('')# - buzznet website

        pygame.init()
        pygame.mixer.init()
        pygame.mixer.music.load("buzznet_pt.mp3")
        pygame.mixer.music.play(0)
        time.sleep(3)
        pygame.mixer.music.load("buzznet_en.mp3")
        pygame.mixer.music.play(0)
        time.sleep(0)

        for x in range(1, 110):
                progress_var.set(x)
                time.sleep(0.05)
                window.update()
                progress_var.set(0)
                            
        webbrowser.open("www.buzznet.com/")
        bot.set('')
####################################################################################################
    elif question in user_5:
        bot.set(choice(bot_info2))
        Utilizador.set('')# - care2 website

        pygame.init()
        pygame.mixer.init()
        pygame.mixer.music.load("care2_pt.mp3")
        pygame.mixer.music.play(0)
        time.sleep(3)
        pygame.mixer.music.load("care2_en.mp3")
        pygame.mixer.music.play(0)
        time.sleep(0)

        for x in range(1, 110):
                progress_var.set(x)
                time.sleep(0.05)
                window.update()
                progress_var.set(0)
                            
        webbrowser.open("https://www.care2.com/")
        bot.set('')
####################################################################################################
    elif question in user_6:
        bot.set(choice(bot_info2))
        Utilizador.set('')# - cafemom website

        pygame.init()
        pygame.mixer.init()
        pygame.mixer.music.load("cafemom_pt.mp3")
        pygame.mixer.music.play(0)
        time.sleep(3)
        pygame.mixer.music.load("cafemom_en.mp3")
        pygame.mixer.music.play(0)
        time.sleep(0)

        for x in range(1, 110):
                progress_var.set(x)
                time.sleep(0.05)
                window.update()
                progress_var.set(0)
                            
        webbrowser.open("https://www.cafemom.com/")
        bot.set('')
####################################################################################################
    elif question in user_7:
        bot.set(choice(bot_info2))
        Utilizador.set('')# - cellufun website

        pygame.init()
        pygame.mixer.init()
        pygame.mixer.music.load("cellufun_pt.mp3")
        pygame.mixer.music.play(0)
        time.sleep(3)
        pygame.mixer.music.load("cellufun_en.mp3")
        pygame.mixer.music.play(0)
        time.sleep(0)

        for x in range(1, 110):
                progress_var.set(x)
                time.sleep(0.05)
                window.update()
                progress_var.set(0)
                            
        webbrowser.open("https://www.cellufun.com/games.asp?v=5gbwc9KMt00")
        bot.set('')
####################################################################################################
    elif question in user_8:
        bot.set(choice(bot_info2))
        Utilizador.set('')# - classmates website

        pygame.init()
        pygame.mixer.init()
        pygame.mixer.music.load("classmates_pt.mp3")
        pygame.mixer.music.play(0)
        time.sleep(3)
        pygame.mixer.music.load("classmates_en.mp3")
        pygame.mixer.music.play(0)
        time.sleep(0)

        for x in range(1, 110):
                progress_var.set(x)
                time.sleep(0.05)
                window.update()
                progress_var.set(0)
                            
        webbrowser.open("https://www.classmates.com/")
        bot.set('')
####################################################################################################
    elif question in user_9:
        bot.set(choice(bot_info2))
        Utilizador.set('')# - deviantart website

        pygame.init()
        pygame.mixer.init()
        pygame.mixer.music.load("deviantart_pt.mp3")
        pygame.mixer.music.play(0)
        time.sleep(3)
        pygame.mixer.music.load("deviantart_en.mp3")
        pygame.mixer.music.play(0)
        time.sleep(0)

        for x in range(1, 110):
                progress_var.set(x)
                time.sleep(0.05)
                window.update()
                progress_var.set(0)
                            
        webbrowser.open("https://www.deviantart.com/")
        bot.set('')
####################################################################################################
    elif question in user_info:
        bot.set(choice(bot_info2))
        Utilizador.set('')
        
        for x in range(1, 110):
                progress_var.set(x)
                time.sleep(0.05)
                window.update()
                progress_var.set(0)
                
        pygame.init()
        pygame.mixer.init()
        pygame.mixer.music.load("nenebot_info_pt.mp3")
        pygame.mixer.music.play(0)
        time.sleep(65)
        pygame.mixer.music.load("nenebot_info_en.mp3")
        pygame.mixer.music.play(0)
        time.sleep(55)
        bot.set('')
####################################################################################################
    else:
        Utilizador.set(choice(error))
        Utilizador.set('')

        pygame.init()
        pygame.mixer.init()
        pygame.mixer.music.load("erro_pt.mp3")
        pygame.mixer.music.play(0)
        time.sleep(3)
        pygame.mixer.music.load("error_en.mp3")
        pygame.mixer.music.play(0)
        time.sleep(3)
        pygame.mixer.quit()   
####################################################################################################
progress_var = tkinter.IntVar()
pb = ttk.Progressbar(window, orient="horizontal", length=400, maximum=100, mode="determinate", var=progress_var)
pb.place(x=100, y=100)

Button(window, text="Pressionar Botão\nPress Button", bg='green yellow', command=main).place(x=250, y=150)
####################################################################################################
class testing:

    def __init__(self, window):

        self.text_btn = tkinter.Button(window, text = "Piadas", command = self.piadas)
        self.text_btn.place(x=150, y=150)

    def piadas(self):

        pygame.init()
        pygame.mixer.init()
        pygame.mixer.music.load("piada1_pt.mp3")
        pygame.mixer.music.play(0)
        time.sleep(20)
        pygame.mixer.music.load("piada2_pt.mp3")
        pygame.mixer.music.play(0)
        time.sleep(20)
        pygame.mixer.music.load("piada3_pt.mp3")
        pygame.mixer.music.play(0)
        time.sleep(20)
        pygame.mixer.music.load("piada4_pt.mp3")
        pygame.mixer.music.play(0)
        time.sleep(20)
        pygame.mixer.music.load("piada5_pt.mp3")
        pygame.mixer.music.play(0)
        time.sleep(20)
        pygame.mixer.music.load("piada6_pt.mp3")
        pygame.mixer.music.play(0)
        time.sleep(20)
        pygame.mixer.music.load("piada7_pt.mp3")
        pygame.mixer.music.play(0)
        time.sleep(20)
        pygame.mixer.music.load("piada8_pt.mp3")
        pygame.mixer.music.play(0)
        time.sleep(20)
        pygame.mixer.music.load("piada9_pt.mp3")
        pygame.mixer.music.play(0)
        time.sleep(20)
        pygame.mixer.music.load("piada10_pt.mp3")
        pygame.mixer.music.play(0)
        time.sleep(20)
        pygame.mixer.quit()      
####################################################################################################
class Clock:
    def __init__(self):
        self.time1 = ''
        self.time2 = time.strftime('%H:%M:%S')
        self.mFrame = Frame()
        self.mFrame.place(x=20, y=100)

        self.watch = Label(self.mFrame, text=self.time2, font=('times',12,'bold'))
        self.watch.pack()

        self.changeLabel()

    def changeLabel(self): 
        self.time2 = time.strftime('%H:%M:%S')
        self.watch.configure(text=self.time2)
        self.mFrame.after(200, self.changeLabel)
####################################################################################################
obj1 = Clock()
geeks_bro = GeeksBro(window)
window.resizable(False,False)
window.mainloop()
Try putting this code in place of if question in user_1 and see if it works at all ?

from concurrent import futures

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)
Pages: 1 2