File: random_appearance.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 (32 lines) | stat: -rw-r--r-- 1,089 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
from guizero import App, Text, TextBox, Slider, PushButton, Combo, Box
from random import randint, choice

colors_text = ["red", "purple", "black", "blue", "green"]
colors_bg = ["pink", "yellow", "orange", "white", "cyan"]
fonts = ["garamond", "arial", "helvetica", "courier new", "times new roman", "comic sans"]

def randomise():
    app.bg = choice(colors_bg)
    for widget in app.children:
        widget.bg = choice(colors_bg)
        widget.text_color = choice(colors_text)
        widget.text_size = randint(8,20)
        widget.font = choice(fonts)

def reset():
    app.bg = None
    app.text_color = None
    app.text_size = None
    app.font = None

app = App(width=300, height=200)

title = Text(app, "Customise your app")
text = TextBox(app, text="then reset to default", width=20)
combo = Combo(app, ["by setting to None"])
code = Text(app, text="widget.bg = None", font="courier new")
box = Box(app, layout="grid")
but_random = PushButton(box, text="random", command=randomise, grid=[0,0])
but_reset = PushButton(box, text="reset", command=reset, grid=[1,0])

app.display()