-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathDemo_Edit_Me_Option.py
More file actions
39 lines (25 loc) · 1.46 KB
/
Demo_Edit_Me_Option.py
File metadata and controls
39 lines (25 loc) · 1.46 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
import PySimpleGUI as sg
"""
Demo "Edit Me" (and Version)
More and more of these Demos are getting an "Edit me" option added.
It's a big time saver to be able to right click and choose "Edit me" to edit a program you're developing.
It's maybe an even bigger time saver if you've not worked on it for some time and have forgotten where
the source code is located on your computer.
You can add this capability to your program by adding a right click menu to your window and calling the
editor that you set up in the global PySimpleGUI options.
A constant MENU_RIGHT_CLICK_EDITME_VER_EXIT, when set at the right click menu shows a "Version" and "Edit Me" meny item.
You will need to have first set up your editor by using the menu in sg.main()
Copyright 2018-2026 PySimpleGUI. All rights reserved.
"""
layout = [[sg.Text('Edit this program by right clicking and choosing "Edit me"')],
[sg.Button('Exit')]]
window = sg.Window('Edit Me Right Click Menu Demo', layout, right_click_menu=sg.MENU_RIGHT_CLICK_EDITME_VER_EXIT)
while True: # Event Loop
event, values = window.read()
if event == sg.WIN_CLOSED or event == 'Exit':
break
if event == 'Edit Me':
sg.execute_editor(__file__)
elif event == 'Version':
sg.popup_scrolled(__file__, sg.get_versions(), location=window.current_location(), keep_on_top=True, non_blocking=True)
window.close()