0

I completed a small project but I do not understand why the Tkinter windows close. I would like the window to stay open so I can keep making it say what I entered as input. Why does it close the window? Any way I can fix it?

Thanks

import tkinter as tk
from tkinter import ttk
import pyttsx3


class Call(tk.Tk):
    def __init__(self):
        super().__init__()


        self.title('Calling System')
        self.geometry('500x300')
        self.resizable(False, False)

        self.numero_label = ttk.Label(self, text = 'Numéro Suivant :')
        self.numero_label.place(x = 10, y = 50)

        self.numero_box = tk.StringVar()
        self.numero_box = ttk.Entry(self)
        self.numero_box.place(x = 226, y = 45)
        self.numero_box.focus()

        self.effacer = ttk.Button(self, text = ('EFFACER'), command = self.efface)
        self.effacer.place(x = 10, y = 200)

        self.appeler = ttk.Button(self, text = ('APPELER'), command = self.appel)
        self.appeler.place(x = 365, y = 200)

        self.quitter = ttk.Button(self, text = ('QUITTER'), command = self.leave)
        self.quitter.place(x = 365, y = 250)

    def leave(self):
        self.quit()

    def efface(self):
        self.numero = self.numero_box.delete(0, 'end')
        self.numero_box.focus()

    def appel(self):
        self.engine = pyttsx3.init()
        self.voices = self.engine.getProperty("voices")
        self.engine.setProperty('rate', 170)
        self.engine.setProperty("voice", self.voices[3].id) #changing the language
        Tosay = ('Le numéro ' + self.numero_box.get() + ' est appelé à la caisse')
        self.engine.say(Tosay)
        self.engine.runAndWait()
        print('Le numéro ' + self.numero_box.get() + ' est appelé à la caisse')
        self.numero_box.delete(0, 'end')
        self.numero_box.focus()

if __name__ == "__main__":
    app = Call()
    app.mainloop()
  • Welcome to Stack Overflow. You've got a ```def quitter(self)``` method and then you have a ```self.quitter = ttk.Button(self, text = ('QUITTER'), command = self.quitter)```. You should change the method name to something less confusing. – ewokx Aug 04 '22 at 02:04
  • It works fine for me (I have changed `self.voices[3].id` to `self.voices[0].id`). The window is kept open after speaking what I input. – acw1668 Aug 04 '22 at 02:18
  • @acw1668 what os are you on? I'm on macos – vintagechocolate Aug 04 '22 at 02:37
  • @vintagechocolate My platform is Windows 7 with Python v3.8.13 and pyttsx3 v2.90. – acw1668 Aug 04 '22 at 04:16

0 Answers0