Graphical interface with Tkinter slowing my code

Asked

Viewed 114 times

0

I’m making a little script to automate some things on Windows only one problem I found is to close it (after having converted to executable with the auto-py-to-exe) has to make millstone trampo, going in the Task Manager and looking for the process there. I started to put a graphical interface so I could display status and be able to close the program more easily. The problem is in the function mainloop() from the main window. I have to put a lot of code to be executed after opening it but the function locks the execution of the program. I have looked for another function that does not have this type of operation but I did not find. They could help me?

Script example:

from tkinter import *
from pynput.keyboard import Key,Controller
import os

def bt_click():
    exit()

window = Tk()
window.resizable(0,0)
window.title("WELCOME !")
window.geometry("680x450+320+150")
lb1 = Label(window,text="Executando...")
lb1.place(x=0,y=0)
bt1 = Button(window,text="Quit",width=25,command=bt_click)
bt1.place(x=250,y=140)
txt1 = Text(window,)
window.mainloop()

k = Controller()
time.sleep(9)
while True:
    time.sleep(3)
    k.press('t')
    k.release('t')
    k.type('/plantar')
    k.press(Key.enter)
    k.release(Key.enter)
    time.sleep(87)
    k.press('t')
    k.release('t')
    k.type('/colher')
    k.press(Key.enter)
    k.release(Key.enter)
  • by what I can deduce, you are trying to use a while(pick up the keyboard inputs) next to a mainloop()? ñ know how to do it right, but it has something like Event bind, where you can pass the pada keys certain tasks

  • Actually my doubt is about the mainloop() locking the program and only perform the next action if the window of the graphical interface is closed. The code that comes after could be another that the result would be the same.

  • then mainloop is an infinite loop, the code will repeat until it is finished, so I recommended the bind, as it will allow you to make keyboard-defined inputs even during the mainloop if ñ wants to try the bind you can try to call the main loop this way: mainloop(n=1)

  • I’m more used to GTK, but as far as I could see, the Destroy command is missing in the bt_click function, take a look at this example https://docs.python.org/3/library/tkinter.html

No answers

Browser other questions tagged

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