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 *
from math import*
def position(event):
x1=event.x
#chaine.configure(text = str(event.x),bg='#000000',fg='#ffffff') # spécificités de la chaine de caractère dans le label du canevas (text = position,bg,fg)
#chaine.place(x=str(event.x-10),y=50) # position de cette chaine (x = abs, y=ord)
canevas.coords(line1,x1,130,x1,50)
canevas.coords(line2,x1,0,x1,40)
canevas.coords(Text1,x1,45)
fen = Tk()
fen.geometry('1000x800')
x1=0
canevas = Canvas(fen, width =200, height =150, bg="#000000")
canevas.place(x = 50,y = 50)
canevas.bind("<Motion>", position)
#chaine = Label(canevas) #label du canevas ICI, la chaine se résume en l'abscisse x
canevas.create_line(0,130,200,130,fill='#ffffff')
for i in range(4):
canevas.create_line(50*i,130,50*i,120,fill='#ffffff')
line1=canevas.create_line(x1,130,x1,50,fill='#ffffff')
line2=canevas.create_line(x1,0,x1,40,fill='#ffffff')
Text1=canevas.create_text(x1,45,fill='#ffffff')
fen.mainloop() |