Skip to content

Instantly share code, notes, and snippets.

@Akkiesoft
Created December 25, 2021 10:37
Show Gist options
  • Select an option

  • Save Akkiesoft/0bd737c7afe4d65e593a2e726762b0ce to your computer and use it in GitHub Desktop.

Select an option

Save Akkiesoft/0bd737c7afe4d65e593a2e726762b0ce to your computer and use it in GitHub Desktop.
keypad sample for guizero
from guizero import App, Box, PushButton, Text
def keypad_update():
result.clear()
result.append("{:,}".format(int(buf)))
def keypad_input(i):
global buf
if i < 10:
if buf == "0":
buf = ""
buf += str(i)
keypad_update()
elif i == 10:
buf = "0"
keypad_update()
elif i == 11:
print(buf)
app = App(title="keypad")
app.full_screen = True
buf = "0"
screen_keypad = Box(app, visible=True, width="fill")
keypad_button = Box(screen_keypad, layout="grid", width="fill", align="left")
keypad_result = Box(screen_keypad, width="fill", align="right")
button = list()
for i in range(0,10):
x = int((i + 2) % 3) if i else 0
y = 3 - int((i + 2) / 3)
button.append(PushButton(keypad_button, text=str(i), grid=[x,y], padx=30, command=keypad_input, args=[i]))
button[i].text_size = 40
button.append(PushButton(keypad_button, text="C", grid=[2,3], padx=30, command=keypad_input, args=[10]))
button.append(PushButton(keypad_button, text="⏎", grid=[0,4,3,4], padx=120, command=keypad_input, args=[11]))
button[10].text_size = 40
button[11].text_size = 40
result = Text(keypad_result, text="0", size=40)
app.display()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment