-
Notifications
You must be signed in to change notification settings - Fork 6
/
15_gui.py
41 lines (27 loc) · 1.09 KB
/
15_gui.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
import random
from payton.scene import Scene
from payton.scene.geometry import Cube
from payton.scene.gui import Button, Hud, Theme, Window, WindowAlignment
scene = Scene()
hud = Hud()
scene.add_object("interface", hud)
def new_cube():
x = random.randint(-5, 5)
y = random.randint(-5, 5)
z = random.randint(0, 5)
obj_count = len(scene.objects)
cube = Cube()
cube.position = [x, y, z]
scene.add_object("cube_{}".format(obj_count), cube)
def print_fps(period, total):
scene.huds["interface"].children["main_window"].children["fps_text"].label = f"FPS: {scene.fps}"
theme = Theme()
theme.text_color = [1.0, 0.0, 0.0]
main_window = Window("GUI Example", width=220, height=600, align=WindowAlignment.LEFT, theme=theme,)
create_cube = Button("New Cube", width=200, height=30, left=10, top=40, on_click=new_cube)
fps_text = Button("Hit Space for FPS", width=200, height=30, left=10, top=80)
main_window.add_child("create_cube", create_cube)
main_window.add_child("fps_text", fps_text)
hud.add_child("main_window", main_window)
scene.create_clock("fps", 0.01, print_fps)
scene.run()