[Tutor] Is IDLE prone to memory losses ?

Jean Montambeault jrm@videotron.ca
Wed, 12 Dec 2001 03:09:44 +0200


OK. If I run this I get the error message following:

====================================

#! /usr/bin/env python

from Tkinter import *

def move():
    "déplacement de la balle"
    global x1, y1, dx, dy, flag
    x1, y1= x1 + dx, y1 + dy
    for c in range[1,6]:
        if c==5:
            c=1
        elif c==1:
            can1.itemconfigure(oval1, fill="red")
        elif c==2:
            can1.itemconfigure(oval1, fill="yellow")
        elif c==3:
            can1.itemconfigure(oval1, fill="green")
        elif c==4:
            can1.itemconfigure(oval1, fill="blue")

    if x1 > 360:
        dx, dy = -17, 17

    if y1 > 360:
        dx, dy = -17, -17

    if x1 < 10:
        dx, dy = 17, -17

    if y1 < 10:
        dx, dy = 17, 17

    can1.coords(oval1, x1, y1, x1+30,  y1+30)
    if flag > 0:
        fen1.after(1, move)        # boucler après 50 millisecondes

def stop_it():
        "arrêt de l'animation"
        global flag
        flag=0

def start_it():
        "démarrage de l'animation"
        global flag
        flag = flag+1         # préférable à flag=1 :
        if flag == 1:           # voir explications dans le texte
            move()

####################PROGRAMME PRINCIPAL#####################

# les variables suivantes seront utilisées de manière globale :
x1, y1 = 200, 0         # coordonnées initiales
dx, dy = 17, 17          # "pas" du déplacement
flag=0                  # commutateur

# Création du widget principal ("patent") :

fen1=Tk()
fen1.title("Exercice d'animation avec Tkinter")
can1=Canvas(fen1, bg="dark gray", height=400, width=400)
can1.pack(side="left")
oval1=can1.create_oval(x1, y1, x1+30, y1+30, width=2, fill="blue")
bou1=Button(fen1, text="Quitter", command=fen1.quit)
bou1.pack(side="bottom")
bou2=Button(fen1, text="Démarrer", command=start_it)
bou2.pack()
bou3=Button(fen1, text="Arrêter", command=stop_it)
bou3.pack()
# Démarrage de l'observateur d'événements (boucle principale) :
#fen1.mainloop()

=============================================

Traceback (most recent call last):
  File "C:\Python21\Lib\lib-tk\Tkinter.py", line 1285, in __call__
    return apply(self.func, args)
  File "C:/Python21/scripts_python/animation_automatique.pyw", line 47, in
start_it
    bou1=Button(fen1, text="Quitter", command=fen1.quit)
  File "C:/Python21/scripts_python/animation_automatique.pyw", line 9, in
move
    if x1 > 360:
TypeError: unsubscriptable object

=============================================

It has no relationship to the (yes : saved) code but only to an earlier
version to wich I added some code. Now do you gang get the same behavior
from IDLE. I recently upgraded from Python 2.0 to 2.1 so I went from IDLE
0.6 to 0.8. Never noticed that behavior before ; did you ? If so what should
I do if anything ? This bug is inconsistent : most of the time, what I
change gets saved.

Jean M.