Advertisement
Carotte

test tk

Nov 12th, 2020 (edited)
521
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.15 KB | None | 0 0
  1. from tkinter import *
  2.  
  3. def rond (event): #Un argument est envoyé automatiquement à la fonction suite au can.bind(...), c'est
  4.     x,y = event.x,event.y #une instance d'une classe qui fournit les coordonnées du clic dans le canvas
  5.                           #par le biais de ses attributs x et y (le nom event est donné à l'argument
  6.                           #conventionnellement
  7.     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"
  8.  
  9. fen = Tk()
  10. can = Canvas(fen, width =200, height =150, bg="light yellow")
  11. can.bind("<Button-1>", rond) #on lie le clic gauche à la fonction "rond"
  12. can.pack()
  13. chaine = Label(fen)
  14. chaine.pack()
  15.  
  16. fen.mainloop()
  17.  
  18.  
  19. from tkinter import *
  20.  
  21. def rond (x,y):
  22.     x,y = 30,30
  23.     chaine.configure(can.create_ovale(x,y, fill='red'))
  24.  
  25. def pointeur(event):
  26.     chaine.configure(text = "Clic détecté en X =" + str(event.x) +\
  27.                             ", Y =" + str(event.y))
  28.  
  29. fen = Tk()
  30. can = Canvas(fen, width =200, height =150, bg="light yellow")
  31. can.bind("<Button-1>", rond)
  32. can.pack()
  33. chaine = Label(fen)
  34. chaine.pack()
  35.  
  36. fen.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement