Bonjour,
J'ai un problème je cherche à créer ceci, mais dans une boucle (c'est juste un exemple) :
J'ai essayé ceci :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 #! /usr/bin/python from Tkinter import * root=Tk() f=Frame(root, height=90, width=190, bd=2, relief=GROOVE) f.place(x=4, y=4) c=Canvas(f, height=80, width=180, bg="white") c.place(x=1, y=1) retc1=c.create_rectangle((0, 2, 18, 50), outline="red", fill="red", width=2) retc2=c.create_rectangle((22, 2, 38, 50), outline="red", fill="red", width=2) retc3=c.create_rectangle((42, 2, 58, 50), outline="red", fill="red", width=2) retc4=c.create_rectangle((62, 2, 78, 50), outline="red", fill="red", width=2) retc5=c.create_rectangle((82, 2, 98, 50), outline="red", fill="red", width=2) root.mainloop()
Ca ne fonctionne pas comme plus haut ... , comment reproduire le premier exemple, mais dans une boucle ? .
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 #! /usr/bin/python from Tkinter import * root=Tk() f=Frame(root, height=90, width=190, bd=2, relief=GROOVE) f.place(x=4, y=4) c=Canvas(f, height=80, width=180, bg="white") c.place(x=1, y=1) n1, n2=0, 22 while n2<=98 : c.create_rectangle((0+(n1*n2), 2, 18+(n1*n2), 50), outline="red", fill="red", width=2) n2=(n1+1)*n2 n1=n1+1 root.mainloop()
Merci d'avance .
a+
Partager