If I have a function called do_stuff(), how do I execute it AFTER a tkinter window named root finishes loading.
Asked
Active
Viewed 1,695 times
2
Person
- 329
- 1
- 2
- 14
-
You can use `after` method with some estimated time. – Piotr Wasilewicz Mar 23 '18 at 06:08
-
Explain, please – Person Mar 23 '18 at 06:25
-
https://stackoverflow.com/questions/25753632/tkinter-how-to-use-after-method You can execute any method after some time. – Piotr Wasilewicz Mar 23 '18 at 06:26
-
1While `after` is a viable option, it's worth to notice, that [`Map/Unmap`](http://tcl.tk/man/tcl8.5/TkCmd/bind.htm#M13) event is another option. – CommonSense Mar 23 '18 at 07:37
-
Have you done any research before asking this question? See [How much research effort is expected of Stack Overflow users?](http://meta.stackoverflow.com/q/261592/7432) – Bryan Oakley Mar 23 '18 at 11:55
2 Answers
0
When a window is placed on screen in X Windows is has been mapped so the Tk <Map> event is raised to let your application know that this window is now created and on-screen. If you only want to handle this once after creation then delete your binding the first time your receive the event as it is sent each time the window is re-mapped on screen. ie: minimize and restore events.
patthoyts
- 30,898
- 3
- 60
- 89
0
Similar to the <Map> event, the <Visibility> event is triggered whenever the window/widget becomes visible. By unbinding in the callback, we can make sure the callback is only called once when the window becomes visible.
def callback():
# your code here
root.unbind('<Visibility>') # only call `callback` the first time `root` becomes visible
root.bind('<Visibility>', callback) # call `callback` whenever `root` becomes visible
Christian Reall-Fluharty
- 658
- 6
- 17