96 lines
2.7 KiB
Python
96 lines
2.7 KiB
Python
|
|
from tkinter import *
|
||
|
|
from random import randrange
|
||
|
|
|
||
|
|
promien = 5
|
||
|
|
listapixeli = []
|
||
|
|
|
||
|
|
|
||
|
|
def zmien_promien(wartosc):
|
||
|
|
global promien
|
||
|
|
promien = int(wartosc)
|
||
|
|
skrajny_x = root.winfo_pointerx()
|
||
|
|
skrajny_y = root.winfo_pointery()
|
||
|
|
canvas_x = skrajny_x - canvas.winfo_rootx()
|
||
|
|
canvas_y = skrajny_y - canvas.winfo_rooty()
|
||
|
|
odswiez_pozycje_kropki(canvas_x, canvas_y)
|
||
|
|
|
||
|
|
|
||
|
|
def odswiez_pozycje_kropki(x, y):
|
||
|
|
global promien
|
||
|
|
canvas.coords(podonzaj, x - promien, y - promien, x + promien, y + promien)
|
||
|
|
|
||
|
|
|
||
|
|
def on_mouse_motion(event):
|
||
|
|
odswiez_pozycje_kropki(event.x, event.y)
|
||
|
|
|
||
|
|
|
||
|
|
def skroluj_suwak(event):
|
||
|
|
obecna = vertical_scale.get()
|
||
|
|
|
||
|
|
if event.num == 4:
|
||
|
|
nowa = obecna + 1
|
||
|
|
elif event.num == 5:
|
||
|
|
nowa = obecna - 1
|
||
|
|
else:
|
||
|
|
nowa = obecna
|
||
|
|
|
||
|
|
vertical_scale.set(nowa)
|
||
|
|
|
||
|
|
|
||
|
|
def lewywci(event):
|
||
|
|
canvas.create_rectangle(event.x, event.y, event.x + 1, event.y + 1)
|
||
|
|
listapixeli.append([event.x, event.y])
|
||
|
|
|
||
|
|
|
||
|
|
def czas(event=None):
|
||
|
|
canvas.delete("all")
|
||
|
|
global t
|
||
|
|
global listapixeli
|
||
|
|
for x, y in listapixeli:
|
||
|
|
listapixeli.remove([x, y])
|
||
|
|
if y == canvas.winfo_height() - 100:
|
||
|
|
listapixeli.append([x, y])
|
||
|
|
canvas.create_rectangle(x, y, x + 1, y + 1)
|
||
|
|
elif [x, y + 1] not in listapixeli:
|
||
|
|
listapixeli.append([x, y + 1])
|
||
|
|
canvas.create_rectangle(x, y + 1, x + 1, y + 2)
|
||
|
|
elif [x + 1, y + 1] not in listapixeli and [x - 1, y + 1] not in listapixeli:
|
||
|
|
if t:
|
||
|
|
listapixeli.append([x + 1, y + 1])
|
||
|
|
canvas.create_rectangle(x + 1, y + 1, x + 2, y + 2)
|
||
|
|
t=False
|
||
|
|
else:
|
||
|
|
listapixeli.append([x - 1, y + 1])
|
||
|
|
canvas.create_rectangle(x - 1, y + 1, x, y + 2)
|
||
|
|
t=True
|
||
|
|
elif [x + 1, y + 1] not in listapixeli:
|
||
|
|
listapixeli.append([x + 1, y + 1])
|
||
|
|
canvas.create_rectangle(x + 1, y + 1, x + 2, y + 2)
|
||
|
|
elif [x - 1, y + 1] not in listapixeli:
|
||
|
|
listapixeli.append([x - 1, y + 1])
|
||
|
|
canvas.create_rectangle(x - 1, y + 1, x, y + 2)
|
||
|
|
else:
|
||
|
|
listapixeli.append([x, y])
|
||
|
|
canvas.create_rectangle(x, y, x + 1, y + 1)
|
||
|
|
|
||
|
|
# print(listapixeli)
|
||
|
|
|
||
|
|
|
||
|
|
t = True
|
||
|
|
root = Tk()
|
||
|
|
canvas = Canvas(root, bg="white", highlightthickness=0)
|
||
|
|
canvas.pack(fill="both", expand=True)
|
||
|
|
|
||
|
|
vertical_scale = Scale(root, from_=1, to=50) # , command=zmien_promien)
|
||
|
|
vertical_scale.place(x=0, rely=0.5, anchor='sw')
|
||
|
|
vertical_scale.set(1)
|
||
|
|
|
||
|
|
podonzaj = canvas.create_rectangle(100, 100, 110, 110, fill="green")
|
||
|
|
|
||
|
|
root.bind("<Motion>", lambda e: [on_mouse_motion, czas])
|
||
|
|
# root.bind_all("<Button-4>", skroluj_suwak)
|
||
|
|
# root.bind_all("<Button-5>", skroluj_suwak)
|
||
|
|
root.bind("<B1-Motion>", lewywci)
|
||
|
|
root.bind("<KeyPress>", czas)
|
||
|
|
root.mainloop()
|