-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExample-1.py
81 lines (64 loc) · 2.89 KB
/
Example-1.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
77
78
79
80
81
from tkinter import Tk, Label, Frame, SOLID, NW, W, LEFT, X
class AnimationButton(Label):
def __init__(self, container, text='Button', event='Enter', bgcolor='green', fgcolor='white', command=None):
Label.__init__(self, container)
self.bgcolor = bgcolor
self.fgcolor = fgcolor
self.text = text
self.command = command
self.__color_number_idx = 0
settings = {'text': text,
'bg': self.__get_colors()[0],
'fg': fgcolor,
'font': ('Verdana', 26, 'bold'),
'highlightthickness': 0,
'highlightbackground': 'black',
'relief': SOLID,
'padx': 20,
'pady': 2}
self.configure(**settings, anchor=W)
self.event(event)
def event(self, event):
self.bind(f'<{event}>', self)
if event == 'Enter':
self.bind('<Button-1>', self)
def __get_colors(self):
animation_colors = {'green': ['#018201', '#009902', '#00b300', '#02cb00', '#00e600', '#00ff01', '#1aff10'],
'blue': ['#012a84', '#00339b', '#003cb4', '#0043ce', '#004de2', '#0353fe', '#1865ff']}
return animation_colors[self.bgcolor]
def __animation(self):
colors = self.__get_colors() + self.__get_colors()[:-1][::-1]
if self.__color_number_idx <= colors.__len__()-1:
self['background'] = colors[self.__color_number_idx]
self.__color_number_idx += 1
self.after(40, self.__animation)
else:
self.__color_number_idx = 0
def __str__(self):
return 'AppButton: ' + self.text
def __dir__(self):
return AnimationButton.__dict__
def __call__(self, mouse):
self.__animation()
if self.command:
return self.command()
print(self.__str__())
@staticmethod
def test():
print('Button Clicked!')
def main():
app = Tk()
app.geometry('650x400')
app['background'] = '#424242'
M = Frame()
M.pack(side=LEFT, padx=15)
AnimationButton(M, text='Monday', bgcolor='green', fgcolor='black').pack(anchor=NW, fill=X)
AnimationButton(M, text='Tuesday', bgcolor='green', fgcolor='black').pack(anchor=NW, fill=X)
AnimationButton(M, text='Wednesday', bgcolor='green', fgcolor='black').pack(anchor=NW, fill=X)
AnimationButton(M, text='Thursday', bgcolor='green', fgcolor='black').pack(anchor=NW, fill=X)
AnimationButton(M, text='Friday', bgcolor='green', fgcolor='black').pack(anchor=NW, fill=X)
AnimationButton(M, text='Saturday', bgcolor='blue').pack(anchor=NW, fill=X)
AnimationButton(M, text='Sunday', bgcolor='blue').pack(anchor=NW, fill=X)
app.mainloop()
if __name__ == '__main__':
main()