TTµPythonSTUDIO

… downloads

READ / COPY / TRY

A small idea.
Genuine Python code.

Examples for the console, editor, and GEM windows. Code remains the same in all website languages.

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

A window with a button

Paste 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()
Download the full example GEMDEMO.PY ↓

A class of its own

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())
Download the full example COUNTER.PY ↓

Catching errors

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')

Lists and memory

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()
Download the full example MAIN.PY ↓

A module from a file

Put COUNTER.PY next to your own script. Imports use the normal Python syntax.

from COUNTER import Counter
counter = Counter()
print(counter.add())
Download the full example COUNTER.PY ↓

The complete examples.

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.

Download all programs and examples ↗

What do you think?

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.

Your name and comment will be visible on the homepage and the associated project site. No email address required. You can delete it via this browser on the site where you post the comment.

Loading comments…