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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
from tkinter import *
# Création et paramètre de la fenêtre
root = Tk()
width_w = 1200
height_w = 800
canvas = Canvas(root, width=width_w, height=height_w, background="white")
canvas.pack(side=RIGHT, padx=5, pady=5)
root.resizable(width=False, height=False)
root.title('Heating Draw')
def action_clic_souris(event):
canvas.focus_set()
x = event.x
y = event.y
i = x // 15 * 15 - 5
j = y // 15 * 15 - 5
canvas.create_rectangle(i, j, i + 15, j + 15, fill="green", tag="rec")
# Création du fichier qui stock les valeurs
with open("valeur_x_y.txt", "a+") as file:
file.write(str(i))
file.write(", ")
file.write(str(j))
file.write("\n")
file.close()
return
def print_grid():
if root.find_withtag('square'):
delete('square')
else:
for x in range(25, width_w - 25, 15):
for y in range(25, height_w - 25, 15):
canvas.create_rectangle(x, y, x + 15, y + 15,
width=2, outline='grey',
fill='white',
tag="square")
def delete(MonTag):
root.delete(root.find_withtag(MonTag))
Frame1 = Frame(root, borderwidth=3, relief=GROOVE)
Frame1.pack(side='top', padx=10, pady=10)
Label(Frame1, text="Option de la grille").pack(padx=10,pady=10)
Button(Frame1, text="Afficher", fg='navy', command=print_grid).pack(side='left', padx=10, pady=10)
# Association clic/action
canvas.bind("<Button-1>", action_clic_souris)
root.mainloop() |
Partager