0

The voice should come after self.scr.mainloop() but it is giving immediately voice. The TKinter after method is executing immediately, then pausing for the 3 second time after execution.

What am I doing wrong? The documentation says the function would be called after the pause time, but it's actually happening before. I want to call audio function in def __init__(self):

    from tkinter import *
    from sqlite3 import *
    from tkinter import messagebox
    import pyttsx3
    import time
    engine = pyttsx3.init()
    voices = engine.getProperty('voices')
    engine.setProperty('voice', voices[1].id)

    admin_username1 = {"Prasham":"123456","Akshat":"0000"}
    costermer_password1 = {"user":"user"}

    class store:
        def __init__(self):
            try:
                self.scr.destroy()
                self.scr=Tk()      
                
            except:
                try:
                    self.scr=Tk()
                except:
                    pass
            
            self.scr.geometry("500x500+500+180")
            self.scr.title("Multipurpose Store")
            self.scr.maxsize("500","500")
            self.scr.minsize("500","500")
            frame1 = Frame(self.scr,borderwidth = 3)
            frame1.pack(pady = 155)
            Label(frame1, text = "Login AS",font = ("Roboto",24),background = "yellow").pack()
            b1 = Button(frame1,text = "Admin login",background = "yellow", command=lambda:self.Adminlogin())
            b1.pack(padx=25,pady =25, side = LEFT)
            b2 = Button(frame1,text = "Customer login",background = "yellow",command=lambda:self.Userlogin())
            b2.pack(padx=20,side = LEFT)

            scr.after(3, self.audio)
            self.scr.mainloop()

        def audio(self):
            
            engine.say('Hello World')
            engine.runAndWait()


        def Adminlogin(self):
            self.scr.destroy()
            self.scr=Tk()  
            self.scr.geometry("500x500+500+180")
            self.scr.title("Multipurpose Store")
            self.scr.maxsize("500","500")
            self.scr.minsize("500","500")
            Label(self.scr, text = "Login Confermation",font = ("Roboto",24)).place(x=115,y=155)
            user = Label(self.scr,text = "Username : ",font = ("Roboto",16))
            password = Label(self.scr,text = "Password : " ,font = ("Roboto",16))
            user.place(x = 125, y = 225)
            password.place(x = 125 ,y = 255 )
            uservalue = StringVar()
            passvalue = StringVar()
            
            global userentry
            global passentry

            userentry = Entry(self.scr, textvariable = uservalue)
            passentry = Entry(self.scr, textvariable = passvalue, show="*")
            userentry.place(x = 255,y =230)
            passentry.place(x = 255,y = 265)
            b3 = Button(self.scr,text = "Home",background = "yellow",command=lambda:self.__init__()).place(x=430,y=0,height=20,width=70)
            b4 = Button(self.scr,text = "login",background = "yellow",command=lambda:self.check1()).place(x=250,y=300,height=20,width=130)
            self.scr.mainloop()

        def Userlogin(self):
            self.scr.destroy()
            self.scr=Tk()  
            self.scr.geometry("500x500+500+180")
            self.scr.title("Multipurpose Store")
            self.scr.maxsize("500","500")
            self.scr.minsize("500","500")
            Label(self.scr, text = "Login Confermation",font = ("Roboto",24)).place(x=115,y=155)
            user = Label(self.scr,text = "Username : ",font = ("Roboto",16))
            password = Label(self.scr,text = "Password : " ,font = ("Roboto",16))
            user.place(x = 125, y = 225)
            password.place(x = 125 ,y = 255 )
            uservalue1 = StringVar()
            passvalue1 = StringVar()

            global userentry
            global passentry
        
            userentry = Entry(self.scr, textvariable = uservalue1)
            passentry = Entry(self.scr, textvariable = passvalue1, show="*")
            userentry.place(x = 255,y =230)
            passentry.place(x = 255,y = 265)
            b3 = Button(self.scr,text = "Home",background = "yellow",command=lambda:self.__init__()).place(x=430,y=0,height=20,width=70)
            b5 = Button(self.scr,text = "login",background = "yellow",command=lambda:self.check1()).place(x=265,y=300,height=20,width=100)
            b6 = Button(self.scr,text = "New User",background = "yellow",command=lambda:self.newuser()).place(x=265,y=327,height=19,width=100)
            self.scr.mainloop()

        def check1(self):

            a = userentry.get()
            b = passentry.get()
            
            if a=="" or b=="":
                messagebox.showerror('ERROR', 'Empty Entry is not allowed')
            
            elif a in admin_username1: 
                if admin_username1[a]==b:
                    messagebox.showinfo('Login', "You have Successfully Log In\nWelcome " +a)
                    self.AdminloginGUI()
                else:
                    messagebox.showerror('ERROR', 'INVALID PASSWORD')
            
            elif a in costermer_password1:
                if costermer_password1[a]==b:
                    messagebox.showinfo('Login', "You have Successfully Log In\nWelcome " +a)
                    self.UserloginGUI()
                else:
                    messagebox.showerror('ERROR', 'INVALID PASSWORD')

            else:
                messagebox.showinfo('ERROR', 'You are Not Registered Yet')

        def AdminloginGUI(self):
            self.scr.destroy()
            self.scr=Tk()  
            self.scr.geometry("500x500+500+180")
            self.scr.title("Admin")
            self.scr.maxsize("500","500")
            self.scr.minsize("500","500")
            b3 = Button(self.scr,text = "Home",background = "yellow",command=lambda:self.__init__()).place(x=430,y=0,height=20,width=70)

        def UserloginGUI(self):
            self.scr.destroy()
            self.scr=Tk()  
            self.scr.geometry("500x500+500+180")
            self.scr.title("User")
            self.scr.maxsize("500","500")
            self.scr.minsize("500","500")
            b3 = Button(self.scr,text = "Home",background = "yellow",command=lambda:self.__init__()).place(x=430,y=0,height=20,width=70)

        def newuser(self):
            self.scr.destroy()
            self.scr=Tk()  
            self.scr.geometry("500x500+500+180")
            self.scr.title("New User")
            self.scr.maxsize("500","500")
            self.scr.minsize("500","500")
            b3 = Button(self.scr,text = "Home",background = "yellow",command=lambda:self.__init__()).place(x=430,y=0,height=20,width=70)

    engine.runAndWait()
    store()
0

1 Answer 1

1

Should be self.scr.after(3000, self.audio) instead of scr.after(3, self.audio) because the delay is in milliseconds.

Also remove engine.runAndWait() before store().

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.