False
Values & logicThe logical value false.
enabled = False… downloads
REFERENCE / PYTHON AND GEM
All 35 Python keywords from the MicroPython lexer used, with explanations and syntax snippets. Below that you will find the native GEM API of version 0.1.
60 concepts
The logical value false.
enabled = FalseNo value; often the result of a function without an explicit return.
value = NoneThe logical value true.
enabled = TrueLogical AND; the right side is only evaluated when necessary.
if ready and enabled:
print("start")Logical OR, with short-circuit evaluation.
name = value or "Atari"Inverts the logical value.
if not ready:
print("wachten")Compares object identity. Use == for equality of values.
if value is None:
print("leeg")Test membership or name the container in a for loop.
print(2 in [1, 2, 3])Begins a conditional block. Indentation determines which lines belong to it.
if score > 10:
print("hoog")Test another condition after if.
elif score == 10:
print("precies")The alternative of if; also useful for loops and try.
else:
print("alternatief")Loops through an iterable such as a list or range.
for i in range(3):
print(i)Repeats as long as a condition is true.
while count < 3:
count += 1Leave the inner loop.
if done:
breakContinues with the next iteration of the inner loop.
if skip:
continueDoes nothing; usable as a temporary empty block.
def later():
passDefines a function. In the console, enter a blank line after the entire block.
def twice(x):
return x * 2Terminates a function and optionally returns a value.
return 42Defines a class with its own methods and data.
class Counter:
def __init__(self):
self.value = 0Creates a small function with one expression.
twice = lambda x: x * 2Returns a value from a generator and saves the resumeable state.
def numbers():
yield 1
yield 2Allows a function to change a name in the module namespace.
global counterFrom a nested function, refers to a name in an encompassing function scope.
nonlocal counterDeletes a name, item, or supported attribute; this is not a guaranteed direct GC round.
del values[0]Starts an error handling block.
try:
value = 1 // 0Catches the appropriate exception from a try block.
except ZeroDivisionError:
print("opgevangen")A cleanup block that is also executed after an exception.
finally:
print("klaar")Throws an exception or rethrows the active exception.
raise ValueError("Ongeldige waarde")Checks an assumption; if false, AssertionError follows when assertions are active.
assert counter == 3Uses a context manager for controlled entry and cleanup. The port supports open() and with for text and binary files.
with resource as value:
print(value)Loads a module, such as the built-in gem or gc module.
import gemImports chosen names from a module.
from COUNTER import CounterProvides a local alias on import or an except binding.
import gc as memoryDefines a coroutine. The syntax is enabled, but this port does not provide a asyncio module or ready-made event loop.
async def task():
return 42Wait for an awaitable within a coroutine. This in itself does not provide GEM or asyncio integration.
result = await task()Creates a GEM window. Dimensions are those of the work area.
window = gem.Window("Hallo Atari", 360, 180)A button within a Window. Link a Python function with on_click.
button = gem.Button(window, "Klik", 16, 32, 140, 28)Shows text. The text property can be changed at runtime.
label = gem.Label(window, "Hallo", 16, 16, 280, 24)A simple text field with mouse focus and keyboard input. on_change responds to input.
field = gem.TextBox(window, "Atari", 16, 48, 240, 24)A check mark of which checked indicates the on/off state.
check = gem.CheckBox(window, "Actief", 16, 96, 240, 24)
check.checked = TrueA radio button; group chooses the group and checks the selection.
radio = gem.RadioButton(window, "Keuze", 16, 16, 160, 24)A list of up to 32 items. Multi_select allows multiple selections.
items = gem.ListBox(window, "", 16, 48, 160, 96)Editable text with a list. The arrow cycles through the items.
choice = gem.ComboBox(window, "", 16, 152, 160, 24)Enables or disables the operation of a control.
button.enabled = FalseShows or hides a control.
label.visible = TrueAdds text to a ListBox or ComboBox.
items.add_item("Eerste")The selected list index; -1 means no selection.
print(items.list_index)Enables multiple selection in a ListBox.
items.multi_select = TrueAsks if a list item is selected.
print(items.selected(0))Changes the selection of a list item.
items.set_selected(0, True)Divides radio buttons into independent groups from 0 to 31.
radio.group = 1Opens the Window. First create the controls and connect their callbacks.
window.show()Close the Window. gem.run returns when all Python windows are closed.
window.close()Reads or changes the text of a supported control or window.
label.text = "De knop werkt!"Reads or changes the state of a CheckBox.
print(check.checked)Connects a click to a function. The handler receives the control as a sender.
button.on_click(clicked)Associates keyboard changes in a TextBox with a function.
field.on_change(changed)Processes GEM events until windows are closed or gem.exit is requested.
gem.run()Exit the GUI event loop. This is not the same as closing the Studio.
gem.exit()Shows a GEM message with OK. Maximum five lines of 38 characters; too long text gives ValueError.
gem.alert("Hallo vanaf de Atari!")No results. Try a different search term or choose all categories.
The eight GEM classes and their methods are specific to this Atari port. Import the module with import gem. Python standard libraries such as Tkinter or Qt are not included.
__debug__ is also listed in the lexer as a special constant. match and case are not a supported pattern matching feature in this port. The present async/await-syntax does not mean that a asynciolibrary is available.
Use the code snippets as syntax explanations; some belong within a larger block or require predefined variables. Full executable examples are on the examples page.
View a complete GEM program →MicroPython is not a full CPython. The forms preview supports f-strings and open() for text and binary files. Os, network, pip and CPython extensions are not available.
Read the manual and verification →Tell us what you make, ask a question or share your experience with the development environments.
The count starts with this update; previous downloads are unknown. ZIP packages and ST images count, not unique individuals.
Loading comments…