A session that lasts
Enter these lines one by one at the console prompt. You see 42 and then 43. The variable remains available.
answer = 6 * 7
answer
answer + 1… downloads
READ / COPY / TRY
Examples for the console, editor, and GEM windows. Code remains the same in all website languages.
Enter these lines one by one at the console prompt. You see 42 and then 43. The variable remains available.
answer = 6 * 7
answer
answer + 1Paste this into the editor and press Ctrl+R. The handler receives the clicked control as a sender.
import gem
window = gem.Window('Mijn Python-app', 360, 180)
label = gem.Label(window, 'Hallo Atari!', 16, 16, 300, 24)
button = gem.Button(window, 'Klik hier', 16, 64, 160, 32)
def clicked(sender):
label.text = 'De knop werkt!'
print('Klik ontvangen')
button.on_click(clicked)
window.show()
gem.run()Classes and methods are regular Python. The provided COUNTER file is also used in the GEM example.
class Counter:
def __init__(self):
self.value = 0
def add(self):
self.value += 1
return self.value
c = Counter()
print(c.add())Catch an expected error with except. The finally block is also executed if an error occurs.
try:
print(1 // 0)
except ZeroDivisionError:
print('Delen door nul is opgevangen')
finally:
print('Klaar met deze poging')The native nuclear test checks large numbers, classes, dictionaries and 100 GC rounds. The explicit gc.collect() call is also available in your own code.
import gc
values = [x * x for x in range(6)]
print(values)
print(2 ** 100)
gc.collect()Put COUNTER.PY next to your own script. Imports use the normal Python syntax.
from COUNTER import Counter
counter = Counter()
print(counter.add())New: FORMDEMO.PY contains all seven controls and can be visually re-edited with Ctrl+D or F8.
GEMDEMO.PY used COUNTER.PY. Download the full package to keep the files together. The test demo MAIN.PY runs in the editor or with TTPY.TOS.
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…