Project: cchess-zero Author: chengstone File: ChessView. Project: python-gui-demos Author: adipandas File: program5. Tk Button2App root tk. Project: python-gui-demos Author: adipandas File: program9. Tk DisplayApp root tk. Project: python-gui-demos Author: adipandas File: program6. Tk entryApp root tk. Project: python-gui-demos Author: adipandas File: program Tk App root tk. Tk NoteBookApp root tk. Tk TopLevelApp root tk. I will try all three solutions on the minimal example from above.
The example with the after method worked pretty well. It was possible to communicate with the bash and to update the GUI with the input of the bash. We will use threading. Thread to get the assumed behavior of our small application. The following small application with a thread has the same behavior as the one with the after method from above.
Save Article. Improve Article. Like Article. Recommended Articles. Article Contributed By :. Easy Normal Medium Hard Expert. Writing code in comment? Please use ide. Load Comments. What's New. Most popular in Python. Tkinter has an answer for that problem: a widget's after method:. The after method doesn't block it actually creates another thread of execution , so execution continues on in your python program after after is called, which means tk.
The after method also allows your widgets to remain responsive to other user input. Try running the following program, and then click your mouse on different spots on the canvas:. The difference is, mainloop is the correct way to code and the infinite loop is subtly incorrect. I suspect, though, that the vast majority of the time, either will work. It's just that mainloop is a much cleaner solution. After all, calling mainloop is essentially this under the covers:.
So, why create your own infinite loop when tkinter already has one you can use? Put in the simplest terms possible: always call mainloop as the last logical line of code in your program.
That's how Tkinter was designed to be used. Python Javascript Linux Cheat sheet Contact. Tkinter understanding mainloop tk.
0コメント