File: demo.py

package info (click to toggle)
python-guizero 1.1.1%2Bdfsg1-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 2,676 kB
  • sloc: python: 6,286; makefile: 28; sh: 17
file content (61 lines) | stat: -rw-r--r-- 1,741 bytes parent folder | download | duplicates (4)
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from guizero import App, Text, PushButton, ButtonGroup, Picture, info, warn

def change_message(message):
    message_text.value = message

# these functions are called in order based on the users actions
def message1():
    change_message("guizero makes creating GUI's easy")
    app.after(2000, message2)

def message2():
    message = "guizero uses events to make things happen\n"
    message += "events are actions, like clicking a push button\n"
    message += "so...  create an event!"
    change_message(message)
    app.after(1000, show_the_button)

def show_the_button():
    button.show()

def clicked_the_button():
    button.hide()
    change_message("well done, you created an event by clicking the button")
    app.after(2000, message3)

def message3():
    message = "events are any action the user takes in your app\n"
    message += "choose carefully"
    change_message(message)
    app.after(1000, show_the_selection)

def show_the_selection():
    selection.show()

def selection_chosen():
    selection.hide()
    if selection.value == "choose me":
        info("well done", "you chose wisely")
        goodbye()
    else:
        warn("arrrgh", "next time, choose wisely!")
        app.after(2000, show_the_selection)

def goodbye():
    change_message("Thanks")
    logo.show()

# create the app and the widgets
app = App()
message_text = Text(app, text = "Welcome to guizero")
button = PushButton(app, clicked_the_button, text = "Click me")
button.hide()
selection = ButtonGroup(app, selected = 0, command = selection_chosen, options = ["choose me", "don't choose me"])
selection.hide()
logo = Picture(app, "guizero.gif")
logo.hide()

# show the first message after 2 seconds
app.after(2000, message1)

app.display()