[python3+tkinter]demande d'aide sur un programme.
bonjour à tous et à toutes.
voila je cherche à faire un programme me permettant de "switcher" d'un élément vers un autre et vice versa.
voila mon code:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| from tkinter import *
##fonctions
def drwcircle1(event):
""
can.create_oval(event.x-10,event.y-10,event.x+10,event.y+10,outline="dark red",width=2)
def drwcircle2(event):
""
can.create_oval(event.x-20,event.y-20,event.x+20,event.y+20,outline="green",width=2)
def swtccirc():
global a
if a == drwcircle1:
a = drwcircle2
elif a == drwcircle2:
a = drwcircle1
#program
a = drwcircle2
#interface
fen = Tk()
can = Canvas(fen,width=200, height=200, bg="white")
can.bind("<Button-1>",a)
can.pack()
Button(fen,text="change circle",command=swtccirc).pack()
fen.mainloop() |
bien entendu celui ci ne fonctionne pas (ca serait tellement plus simple). alors j'ai tenté de faire un autre code (à peu près sur le même principe)
le voici:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| from tkinter import *
#fonctions
def drwcircle():
#canv.create_oval(50,50,150,150,outline="red")
canv.create_oval(50,50,150,150,outline=coul)
def chngcoul():
global coul
if coul == "red":
coul = "green"
elif coul == "green":
coul = "red"
#programme
coul="red"
#grahpique
fen = Tk()
canv = Canvas(fen,width=200,height=200,bg="white")
canv.pack()
Button(fen,text="change color",command=chngcoul).pack(side=BOTTOM)
Button(fen,text="drwcircle",command=drwcircle).pack()
fen.mainloop() |
donc dans celui-ci la couleur change bien. dans le 1er je désire que le cercle change.
merci pour vos explications et votre aide.
cdt