superace
Posts: 40
Joined: Thu Feb 25, 2016 12:02 pm

Thonny python block indent?

Sun Jul 14, 2019 1:51 am

Hi
I just finished a summer activity using Pi3B+ and Thonny Python. 9 kids (8-11 yo) first week, 10 kids (10-12 yo) second week. 15 out of 19 kids were girls. Thonny is perfect for my camps because it can run the code on an external Micropython board in a very easy way.

Everyone loved it and were super excited but.....

Because the kids don't really see the "logical flow" when they start coding they must add features "a long the way". I can not find where to do Block Indent/De-indent in Thonny. Is there such feature?

Example they write a blinky light SW: (Of course this code only runs once and it's example code so it does not really work I know.)

Code: Select all

for n in range(1,10):
    light.on()
    time.sleep(1)
    light.off()
    time.sleep(1)
So now they want to add code to make this run always in a loop.
Because "while" is indented and "for" is indented they must manually correct this when they modify the code giving much trouble and possibilities for simple mistakes. Of course this example is only a few lines but few programs are this simple.

In IDLE the block indent/de-indent function was perfect for this. One of the few good things in IDLE perhaps.

Code: Select all

while True:
    for n in range(1,10):
        light.on()
        time.sleep(1)
        light.off()
        time.sleep(1)
It is my impression Thonny is being pushed as a favorite for python coding on Raspberry given that IDLE is no longer a standard menu option.

Any thoughts here? What am I missing?

User avatar
rpiMike
Posts: 835
Joined: Fri Aug 10, 2012 12:38 pm
Location: Cumbria, UK

Re: Thonny python block indent?

Sun Jul 14, 2019 7:43 am

Highlight the lines that you want to indent then press <tab>. To outdent press <shift><tab>.

Return to “Python”