micropython-micro-gui/gui/demos/simple.py

41 wiersze
1.1 KiB
Python
Czysty Zwykły widok Historia

2021-06-09 16:11:48 +00:00
# simple.py Minimal micro-gui demo.
2021-06-23 17:05:14 +00:00
# Released under the MIT License (MIT). See LICENSE.
2024-09-20 08:15:32 +00:00
# Copyright (c) 2021-2024 Peter Hinch
2021-06-23 17:05:14 +00:00
# hardware_setup must be imported before other modules because of RAM use.
import hardware_setup # Create a display instance
from gui.core.ugui import Screen, ssd
2021-06-09 16:11:48 +00:00
2022-02-06 12:05:38 +00:00
from gui.widgets import Label, Button, CloseButton
2021-06-09 16:11:48 +00:00
from gui.core.writer import CWriter
# Font for CWriter
import gui.fonts.arial10 as arial10
from gui.core.colors import *
class BaseScreen(Screen):
def __init__(self):
def my_callback(button, arg):
2024-09-20 08:15:32 +00:00
print("Button pressed", arg)
2021-06-09 16:11:48 +00:00
super().__init__()
wri = CWriter(ssd, arial10, GREEN, BLACK)
2021-06-09 16:11:48 +00:00
col = 2
row = 2
2024-09-20 08:15:32 +00:00
Label(wri, row, col, "Simple Demo")
2021-06-25 15:56:14 +00:00
row = 50
2024-09-20 08:15:32 +00:00
Button(wri, row, col, text="Yes", callback=my_callback, args=("Yes",))
2021-06-09 16:11:48 +00:00
col += 60
2024-09-20 08:15:32 +00:00
Button(wri, row, col, text="No", callback=my_callback, args=("No",))
2021-06-09 16:11:48 +00:00
CloseButton(wri) # Quit the application
2024-09-20 08:15:32 +00:00
2021-06-09 16:11:48 +00:00
def test():
2024-09-20 08:15:32 +00:00
print("Simple demo: button presses print to REPL.")
2021-06-23 17:05:14 +00:00
Screen.change(BaseScreen) # A class is passed here, not an instance.
2021-06-09 16:11:48 +00:00
2024-09-20 08:15:32 +00:00
2021-06-09 16:11:48 +00:00
test()