forked from amalkhatib90/Project01
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwindow_functions.py
More file actions
44 lines (30 loc) · 1.03 KB
/
window_functions.py
File metadata and controls
44 lines (30 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
def center_window(window):
"""
centers the given window/widget on the screen
Args:
window: the tk window (root/toplevel) instance to center
"""
window.update_idletasks()
# get current window width & height
width = window.winfo_width()
height = window.winfo_height()
# calculate centered x and y
x = (window.winfo_screenwidth() // 2) - (width // 2)
y = (window.winfo_screenheight() // 2) - (height // 2)
# resize window
window.geometry('{0}x{1}+{2}+{3}'.format(width, height, x, y))
# this prevents window from temporarily appearing in its original position
window.withdraw()
window.deiconify()
def position_window(window, x, y):
"""
sends the given window to the given x, y position
Args:
window: the tk window (root/toplevel) instance to move
x: pixel x-position to move to
y: pixel y-position to move to
"""
window.update_idletasks()
window.geometry('+{}+{}'.format(x, y))
window.withdraw()
window.deiconify()