-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcbutton.py
More file actions
37 lines (23 loc) · 957 Bytes
/
cbutton.py
File metadata and controls
37 lines (23 loc) · 957 Bytes
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
import tkinter
class Canvas(tkinter.Canvas):
def create_button(self, *args, **kw) -> int:
x, y, cx, cy = args
text = kw["text"]
command = kw["command"]
button_id = self.create_rectangle(x, y, cx, cy, fill="white")
self.create_text(x + (cx - x) // 2, y + (cy - y) // 2, text=text, state="disabled")
self.tag_bind(button_id, "<Button-1>", command)
return button_id
WIDTH = 500
HEIGHT = 500
MASTER = tkinter.Tk()
MASTER.title("Canvas buttons")
CANVAS = Canvas(MASTER, bg="white", width=WIDTH, height=HEIGHT)
def create_new(event: tkinter.Event) -> None:
CANVAS.create_button(event.x - 50, event.y - 50, event.x + 50, event.y + 50, text="test", command=create_new)
def main() -> None:
test = CANVAS.create_button(100, 100, 200, 200, text="test", command=create_new)
CANVAS.pack()
MASTER.mainloop()
if __name__ == '__main__':
main()