Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from tkinter import *
- def rond (event): #Un argument est envoyé automatiquement à la fonction suite au can.bind(...), c'est
- x,y = event.x,event.y #une instance d'une classe qui fournit les coordonnées du clic dans le canvas
- #par le biais de ses attributs x et y (le nom event est donné à l'argument
- #conventionnellement
- can.create_oval(x-5,y-5,x+5,y+5, fill='red') #on crée un cercle de centre les coordonnées du clic dans notre Canvas "can"
- fen = Tk()
- can = Canvas(fen, width =200, height =150, bg="light yellow")
- can.bind("<Button-1>", rond) #on lie le clic gauche à la fonction "rond"
- can.pack()
- chaine = Label(fen)
- chaine.pack()
- fen.mainloop()
- from tkinter import *
- def rond (x,y):
- x,y = 30,30
- chaine.configure(can.create_ovale(x,y, fill='red'))
- def pointeur(event):
- chaine.configure(text = "Clic détecté en X =" + str(event.x) +\
- ", Y =" + str(event.y))
- fen = Tk()
- can = Canvas(fen, width =200, height =150, bg="light yellow")
- can.bind("<Button-1>", rond)
- can.pack()
- chaine = Label(fen)
- chaine.pack()
- fen.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement