Je reçois l'erreur suivante:_tkinter.TclError: nom de la commande non valide » 0,14574424"
_tkinter.TclError: invalid command name “.14574424”
Je ne suis pas en mesure de comprendre l'erreur. Qu'est-ce que je fais mal?
# Import tkinter
from tkinter import *
class AnimationDemo:
def __init__(self):
window = Tk() # Create a window
window.title("Animation Demo") # Set a title
width = 250 # Width of the canvas
canvas = Canvas(window, bg = "white", width = 250, height = 50)
canvas.pack()
x = 0 # Starting x position
canvas.create_text(x, 30, text = "Message moving?", tags = "text")
dx = 3
while True:
canvas.move("text", dx, 0) # Move text dx unit
canvas.after(100) # Sleep for 100 milliseconds
canvas.update() # Update canvas
if x < width:
x += dx # Get the current position for string
else:
x = 0 # Reset string position to the beginning
canvas.delete("text")
# Redraw text at the beginning
canvas.create_text(x, 30, text = "Message moving?", tags = "text")
window.mainloop() # Create an event loop
AnimationDemo() # Create GUI
erreur: Traceback (appel le plus récent en dernier): Fichier « D : /sem4/t/lesson4/task1/task.py ", ligne 29, dans AnimationDemo() # Créer une interface utilisateur graphique Fichier" D: /sem4/t/lesson4/task1/task.py ", ligne 17, dans __init__ canvas.move ("text", dx, 0) # Déplacer le texte unité dx F ile "C: \ Utilisateurs \ sreeyu \ AppData \ Local \ Programmes \ Python \ Python35 \ lib \ tkinter \ __ init__.py", ligne 2431, en déplacement self.tk.call ((self._w, 'move') + args) _tkinter.TclError: nom de commande invalide ".14440096" –
hss
Que faites-vous qui provoque l'erreur? En passant, c'est la mauvaise façon de faire de l'animation avec Tkinter. Voir http://stackoverflow.com/a/11505034/7432 –
Merci @BryanOakley mais peut-être je sais pourquoi il montre l'erreur si nous avons utilisé la boucle – hss