-
Notifications
You must be signed in to change notification settings - Fork 0
/
vaba_joonistamine_klassidega.py
56 lines (45 loc) · 2.03 KB
/
vaba_joonistamine_klassidega.py
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
54
55
56
from tkinter import *
from tkinter.ttk import *
class JoonistamiseApp(Tk):
def __init__(self):
Tk.__init__(self) # ülemklassi intsialiseerimismeetodi väljakutse
# Tekita objektid
self.c = Canvas(self, bg="white")
self.koord_str = StringVar()
self.koordinaadid = Label(self, textvariable=self.koord_str)
# Paiguta objektid
self.rowconfigure(0, weight=1)
self.columnconfigure(0, weight=1)
self.c.grid(row=0, column=0, sticky=(N, S, W, E))
self.koordinaadid.grid(row=1, column=0)
# Seosta funktsioonidega
self.c.bind("<Button-1>", self.vasak_nupp)
self.c.bind("<Button-2>", self.keskmine_nupp)
self.c.bind("<Button-3>", self.parem_nupp)
self.c.bind("<B1-Motion>", self.vasakuga_lohistamine)
self.c.bind("<B1-ButtonRelease>", self.vasaku_vabastamine)
self.alg_x = 0
self.alg_y = 0
self.abijoone_id = None
def vasak_nupp(self, event):
#global alg_x, alg_y
self.koord_str.set("X: " + str(event.x) + ", Y: " + str(event.y))
self.alg_x = event.x
self.alg_y = event.y
def keskmine_nupp(self, event):
self.koord_str.set("X: " + str(event.x) + ", Y: " + str(event.y))
self.c.create_line(event.x, event.y-5, event.x, event.y+5)
self.c.create_line(event.x-5, event.y, event.x+5, event.y)
def parem_nupp(self, event):
self.koord_str.set("X: " + str(event.x) + ", Y: " + str(event.y))
self.c.create_oval(event.x-5, event.y-5, event.x+5, event.y+5)
def vasakuga_lohistamine(self, event):
#global abijoone_id
self.koord_str.set("X: " + str(event.x) + ", Y: " + str(event.y))
self.c.delete(self.abijoone_id)
self.abijoone_id = self.c.create_line(self.alg_x, self.alg_y, event.x, event.y)
def vasaku_vabastamine(self, event):
#global abijoone_id
self.abijoone_id = None
root = JoonistamiseApp()
root.mainloop()