2 Ce module contient la fonction utilitaire centerwindow
3 qui sert à centrer une fenetre
7 def centerwindow(window,parent = 'avec'):
9 parent = window.winfo_parent()
10 if type(parent) == types.StringType:
11 parent = window._nametowidget(parent)
12 # Find size of window.
13 window.update_idletasks()
14 width = window.winfo_width()
15 height = window.winfo_height()
16 if width == 1 and height == 1:
17 # If the window has not yet been displayed, its size is
18 # reported as 1x1, so use requested size.
19 width = window.winfo_reqwidth()
20 height = window.winfo_reqheight()
21 # Place in centre of screen:
23 x = (window.winfo_screenwidth() - width) / 2 - parent.winfo_vrootx()
24 y = (window.winfo_screenheight() - height) / 3 - parent.winfo_vrooty()
26 x = (window.winfo_screenwidth() - width) / 2
27 y = (window.winfo_screenheight() - height) / 3
32 window.geometry('+%d+%d' % (x, y))