Tkinter python program seem to work without a mainloop, why?

  Kiến thức lập trình

With this small PYTHON code:
import time
def toto(num=-1):
for i in range(10):
print (‘toto:’,num,’ :: loop:’,i,flush=True)
time.sleep(1)

app=tk.Tk()#bg='black')
app.geometry('+600+600')
tk.Button(app,text='MAIN_BUTTON1',command=lambda a=-1: toto(a)).grid()
print ("APP=",app)
"""app2=tk.Tk()#bg='black')
app2.geometry('+300+300')
tk.Button(app2,text='MAIN_BUTTON2',command=lambda a=-2: toto(a)).grid()
print ("APP2=",app2)"""

input()

When i run it in a linux KDE Konsole terminal, i can press the ‘MAIN_BUTTON1’ and activate toto function. It seem like the standard input() function while waiting keyboard input permit Ui event to be executed by ????
is anyone have an idea. Perhaps this only happen inside linux and KDE?

I just use input with the goal to step(block) the entire program for debugging purpose. The effect is strange for me, but i am not a professional.

New contributor

waldo kiti fra is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

LEAVE A COMMENT