Tkinter Python stopping the script

Asked

Viewed 89 times

1

Good afternoon,

I would like to create a window with the words "Application running" and tried the following:

from Tkinter import *
root = Tk()
T = Text(root, height=2, width=30)
T.pack()
T.insert(END, "Aplicação rodando")
mainloop()
*** Resto do meu script aqui... ***

However I noticed that my script only starts running when I close the window created by Tkinter, it is possible to keep the window open while my script is running ?

  • Yes, it does, but you know what the function mainloop ago?

  • Opa Anderson, in vdd I have no idea. My current script records an audio via microphone, transforms it into an audio file, this audio file is processed and what the user says returns in a . txt, however I noticed that the user did not know that was being recorded and wanted something very synthetic so I just tried to copy a script from the internet.

  • Take the @Andersoncarloswoss tip and study what mainloop() ago.

1 answer

3


The problem is that the line mainloop() is holding the execution. This function gives Tkinter control of the script, so that it responds to events such as pressing buttons, etc, until it is closed.

To prevent Tkinter from doing this, remove this line. Put root.update() instead to update the screen, and your script will continue running (but without responding to window events)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.