-
Notifications
You must be signed in to change notification settings - Fork 4
/
08-events-cancel.py
42 lines (36 loc) · 1.19 KB
/
08-events-cancel.py
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
#
# (C) Copyright 2024 Pavel Tisnovsky
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v10.html
#
# Contributors:
# Pavel Tisnovsky
#
#
# link to source:
# https://github.com/tisnik/most-popular-python-libs/blob/master/PySimpleGUI/08-events-cancel.py
#
# link to source in literate programming format:
# https://tisnik.github.io/most-popular-python-libs/PySimpleGUI/08-events-cancel.html
import PySimpleGUI as sg
# ovládací prvky, které se mají zobrazit v okně
layout = [
[sg.Text("Hello, world!"), sg.Button("Button1")],
[sg.InputText()],
[sg.Submit(), sg.Cancel(), sg.Exit()],
]
# vytvoření okna s ovládacími prvky
window = sg.Window("Window #7", layout)
# obsluha smyčky událostí (event loop)
while True:
# přečtení události
event, values = window.read()
print("Event: ", event, " Values: ", values)
# reakce na událost "uzavření okna"
if event in {sg.WIN_CLOSED, "Exit"}:
break
# po výskoku ze smyčky událostí aplikaci ukončíme
window.close()