-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathDemo_Auto_Save_Window_Position.py
More file actions
31 lines (20 loc) · 1.16 KB
/
Demo_Auto_Save_Window_Position.py
File metadata and controls
31 lines (20 loc) · 1.16 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
import PySimpleGUI as sg
"""
Simple template window that saves position.
Rather than starting in the middle of the screen, this code will save the position the window was in when it last exited.
To pull this off it's going to be.... super.....?hard?
No... of course it's going to be... SIMPLE
There is one added line of code. When the user attempts to close the window, that's when the position is saved.
When the program starts, it reads the previously saved position as part of the window creation. User Settings APIs rock!
Copyright 2018-2026 PySimpleGUI. All rights reserved.
"""
layout = [[sg.Text('Window that Auto-saves position', font='_ 25')],
[sg.Button('Ok'), sg.Button('Exit')]]
window = sg.Window('Auto-saves Location', layout, enable_close_attempted_event=True, location=sg.user_settings_get_entry('-location-', (None, None)))
while True:
event, values = window.read()
print(event, values)
if event in ('Exit', sg.WINDOW_CLOSE_ATTEMPTED_EVENT):
sg.user_settings_set_entry('-location-', window.current_location()) # The line of code to save the position before exiting
break
window.close()