-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStylizedButton.py
76 lines (68 loc) · 3.36 KB
/
StylizedButton.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
from prerequisites import *
from requisites import *
from tkinter import *
class StylizedButton(Label):
# def __init__(self, master, **kwargs) -> None:
# self.master = master
# self.config(**kwargs)
def __init__(self, master, stylized_prop={}, command=None, image=None, **kwargs):
Label.__init__(self, master, **kwargs)
if stylized_prop == {}:
stylized_prop = {
"radius": int(self.winfo_height() / 2),
"resolution": 5,
"fill_color": "white",
"border_color": "darkgreen",
"border_width": 2,
"font_name": "comicz.ttf",
"font_size": 20,
"font_color": "darkgreen",
"font_style": "italic"
}
self.fontprop = (stylized_prop["font_name"], stylized_prop["font_size"], stylized_prop["font_color"], stylized_prop["font_style"])
self.command = command
self.image = PhotoImage(file=rounded_rectangle(width=200,
height=200,
radius=100,
font_prop=self.fontprop,
fill_color="green",
border_width=5))
self.config(image=self.image)
self.bind('<Button-1>', self.on_click)
self.bind('<Enter>', self.on_enter)
self.bind('<Leave>', self.on_leave)
def on_enter(self, event):
self.image = PhotoImage(file=rounded_rectangle(width=200,
height=200,
radius=100,
font_prop=self.fontprop,
fill_color="red",
border_width=5))
self.configure(image=self.image)
# self.config(bg='#0099CC')
def on_leave(self, event):
self.image = PhotoImage(file=rounded_rectangle(width=200,
height=200,
radius=100,
font_prop=self.fontprop,
fill_color="green",
border_width=5))
self.config(image=self.image)
# self.config(bg='#006699')
def on_click(self, event):
self.image = PhotoImage(file=rounded_rectangle(width=200,
height=200,
radius=100,
font_prop=self.fontprop,
fill_color="blue",
border_width=5))
self.config(image=self.image)
self.command()
if __name__ == '__main__':
root = Tk()
root.geometry('300x300')
root.title('Stylized Button')
root.resizable(False, False)
test_button = StylizedButton(root, 'Test', command=lambda: print('Test'))
test_button.pack()
root.mainloop()