3

If I have a called do_stuff(), how do I execute it AFTER a window named root finishes loading.

Person
  • 379
  • 1
  • 3
  • 15

2 Answers2

1

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
  • While `` probably is better for some purposes, I was trying to center the window, and the geometry didn't seem finalized by the time `` was triggered, so `` was the next best option – Christian Reall-Fluharty Oct 23 '20 at 05:56
-1

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
  • 32,320
  • 3
  • 62
  • 93
  • 1
    umm... How again? – Person Mar 25 '18 at 02:35
  • The question asked about fully loaded window aka all inner widgets are loaded as well. is triggered earlier. You can check it by updating the window geometry and then binding window to print(window.geometry()). The reported value will differ from the required one. – Andrey Dec 08 '22 at 16:45