tkfluent 0.1.0__py3-none-any.whl → 0.1.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- tkflu/__main__.py +5 -6
- tkflu/badge.py +2 -0
- tkflu/button.py +104 -20
- tkflu/bwm.py +10 -5
- tkflu/demos/designer.py +33 -0
- tkflu/demos/grad2.py +10 -133
- tkflu/demos/grad3.py +6 -12
- tkflu/designs/__init__.py +1 -0
- tkflu/designs/animation.py +37 -0
- tkflu/designs/gradient.py +2 -0
- tkflu/designs/label.py +10 -0
- tkflu/designs/menubar.py +0 -3
- tkflu/designs/primary_color.py +5 -5
- tkflu/frame.py +32 -4
- tkflu/label.py +29 -16
- tkflu/menu.py +1 -1
- tkflu/menubar.py +17 -12
- tkflu/thememanager.py +22 -4
- tkflu/togglebutton.py +10 -17
- tkflu/toplevel.py +17 -1
- tkfluent-0.1.2.dist-info/METADATA +323 -0
- {tkfluent-0.1.0.dist-info → tkfluent-0.1.2.dist-info}/RECORD +23 -20
- tkfluent-0.1.0.dist-info/METADATA +0 -83
- {tkfluent-0.1.0.dist-info → tkfluent-0.1.2.dist-info}/WHEEL +0 -0
tkflu/__main__.py
CHANGED
@@ -2,7 +2,9 @@ from tkflu import *
|
|
2
2
|
from tkinter import *
|
3
3
|
from tkinter.font import *
|
4
4
|
|
5
|
-
|
5
|
+
orange_primary_color()
|
6
|
+
set_animation_steps(10)
|
7
|
+
set_animation_step_time(20)
|
6
8
|
|
7
9
|
def togglestate():
|
8
10
|
if button1.dcget("state") == NORMAL:
|
@@ -103,9 +105,6 @@ togglebutton3.pack(fill="x", padx=5, pady=5)
|
|
103
105
|
entry1 = FluEntry(frame)
|
104
106
|
entry1.pack(fill="x", padx=5, pady=5)
|
105
107
|
|
106
|
-
entry2 = FluEntry(frame, height=50)
|
107
|
-
entry2.pack(fill="x", padx=5, pady=5)
|
108
|
-
|
109
108
|
text1 = FluText(frame)
|
110
109
|
text1.pack(fill="x", padx=5, pady=5)
|
111
110
|
|
@@ -116,6 +115,6 @@ slider1.pack(fill="x", padx=5, pady=5)
|
|
116
115
|
listbox1.dconfigure()
|
117
116
|
listbox1.pack(fill="x", padx=5, pady=5)"""
|
118
117
|
|
119
|
-
frame.pack(fill="both", expand="yes", side="right", padx=
|
120
|
-
|
118
|
+
frame.pack(fill="both", expand="yes", side="right", padx=15, pady=15)
|
119
|
+
frame.update_idletasks()
|
121
120
|
root.mainloop()
|
tkflu/badge.py
CHANGED
@@ -142,6 +142,8 @@ class FluBadge(FluBadgeCanvas, DDrawWidget, FluToolTipBase):
|
|
142
142
|
fill=_text_color, text=self.attributes.text, font=self.attributes.font
|
143
143
|
)
|
144
144
|
|
145
|
+
self.after(10, lambda: self.update())
|
146
|
+
|
145
147
|
def theme(self, mode=None, style=None):
|
146
148
|
if mode:
|
147
149
|
self.mode = mode
|
tkflu/button.py
CHANGED
@@ -63,8 +63,9 @@ class FluButtonCanvas(DCanvas):
|
|
63
63
|
|
64
64
|
from .constants import MODE, STATE, BUTTONSTYLE
|
65
65
|
from .tooltip import FluToolTipBase
|
66
|
+
from .designs.gradient import FluGradient
|
66
67
|
|
67
|
-
class FluButton(FluButtonCanvas, DDrawWidget, FluToolTipBase):
|
68
|
+
class FluButton(FluButtonCanvas, DDrawWidget, FluToolTipBase, FluGradient):
|
68
69
|
def __init__(self, *args,
|
69
70
|
text="",
|
70
71
|
width=120,
|
@@ -102,6 +103,9 @@ class FluButton(FluButtonCanvas, DDrawWidget, FluToolTipBase):
|
|
102
103
|
|
103
104
|
from easydict import EasyDict
|
104
105
|
|
106
|
+
self.enter = False
|
107
|
+
self.button1 = False
|
108
|
+
|
105
109
|
self.attributes = EasyDict(
|
106
110
|
{
|
107
111
|
"text": "",
|
@@ -118,7 +122,7 @@ class FluButton(FluButtonCanvas, DDrawWidget, FluToolTipBase):
|
|
118
122
|
|
119
123
|
self.theme(mode=mode, style=style)
|
120
124
|
|
121
|
-
def _draw(self, event=None):
|
125
|
+
def _draw(self, event=None, tempcolor: dict = None):
|
122
126
|
super()._draw(event)
|
123
127
|
|
124
128
|
width = self.winfo_width()
|
@@ -130,26 +134,37 @@ class FluButton(FluButtonCanvas, DDrawWidget, FluToolTipBase):
|
|
130
134
|
|
131
135
|
_dict = None
|
132
136
|
|
133
|
-
if
|
134
|
-
if
|
135
|
-
if self.
|
136
|
-
|
137
|
+
if not tempcolor:
|
138
|
+
if state == "normal":
|
139
|
+
if self.enter:
|
140
|
+
if self.button1:
|
141
|
+
_dict = self.attributes.pressed
|
142
|
+
else:
|
143
|
+
_dict = self.attributes.hover
|
137
144
|
else:
|
138
|
-
_dict = self.attributes.
|
145
|
+
_dict = self.attributes.rest
|
139
146
|
else:
|
140
|
-
_dict = self.attributes.
|
147
|
+
_dict = self.attributes.disabled
|
148
|
+
|
149
|
+
_back_color = _dict.back_color
|
150
|
+
_back_opacity = _dict.back_opacity
|
151
|
+
_border_color = _dict.border_color
|
152
|
+
_border_color_opacity = _dict.border_color_opacity
|
153
|
+
_border_color2 = _dict.border_color2
|
154
|
+
_border_color2_opacity = _dict.border_color2_opacity
|
155
|
+
_border_width = _dict.border_width
|
156
|
+
_radius = _dict.radius
|
157
|
+
_text_color = _dict.text_color
|
141
158
|
else:
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
_radius = _dict.radius
|
152
|
-
_text_color = _dict.text_color
|
159
|
+
_back_color = tempcolor.back_color
|
160
|
+
_back_opacity = tempcolor.back_opacity
|
161
|
+
_border_color = tempcolor.border_color
|
162
|
+
_border_color_opacity = tempcolor.border_color_opacity
|
163
|
+
_border_color2 = tempcolor.border_color2
|
164
|
+
_border_color2_opacity = tempcolor.border_color2_opacity
|
165
|
+
_border_width = tempcolor.border_width
|
166
|
+
_radius = tempcolor.radius
|
167
|
+
_text_color = tempcolor.text_color
|
153
168
|
|
154
169
|
self.element_border = self.create_round_rectangle(
|
155
170
|
0, 0, width, height, _radius, temppath=self.temppath,
|
@@ -164,6 +179,8 @@ class FluButton(FluButtonCanvas, DDrawWidget, FluToolTipBase):
|
|
164
179
|
fill=_text_color, text=self.attributes.text, font=self.attributes.font
|
165
180
|
)
|
166
181
|
|
182
|
+
self.update()
|
183
|
+
|
167
184
|
def theme(self, mode: MODE = None, style: BUTTONSTYLE = None):
|
168
185
|
if mode:
|
169
186
|
self.mode = mode
|
@@ -184,11 +201,78 @@ class FluButton(FluButtonCanvas, DDrawWidget, FluToolTipBase):
|
|
184
201
|
else:
|
185
202
|
self._light()
|
186
203
|
|
187
|
-
def _theme(self, mode, style):
|
204
|
+
def _theme(self, mode, style, animation_steps: int = None, animation_step_time: int = None):
|
205
|
+
if animation_steps is None:
|
206
|
+
from .designs.animation import get_animation_steps
|
207
|
+
animation_steps = get_animation_steps()
|
208
|
+
if animation_step_time is None:
|
209
|
+
from .designs.animation import get_animation_step_time
|
210
|
+
animation_step_time = get_animation_step_time()
|
188
211
|
r = button(mode, style, "rest")
|
189
212
|
h = button(mode, style, "hover")
|
190
213
|
p = button(mode, style, "pressed")
|
191
214
|
d = button(mode, style, "disabled")
|
215
|
+
if self.dcget("state") == "normal":
|
216
|
+
if self.enter:
|
217
|
+
if self.button1:
|
218
|
+
now = p
|
219
|
+
else:
|
220
|
+
now = h
|
221
|
+
else:
|
222
|
+
now = r
|
223
|
+
else:
|
224
|
+
now = d
|
225
|
+
#print(animation_step_time)
|
226
|
+
#print(type(animation_step_time))
|
227
|
+
if hasattr(self.attributes.rest, "back_color"):
|
228
|
+
back_colors = self.generate_hex2hex(
|
229
|
+
self.attributes.rest.back_color, now["back_color"], animation_steps
|
230
|
+
)
|
231
|
+
border_colors = self.generate_hex2hex(
|
232
|
+
self.attributes.rest.border_color, now["border_color"], animation_steps
|
233
|
+
)
|
234
|
+
if self.attributes.rest.border_color2 is None:
|
235
|
+
self.attributes.rest.border_color2 = self.attributes.rest.border_color
|
236
|
+
if now["border_color2"] is None:
|
237
|
+
now["border_color2"] = now["border_color"]
|
238
|
+
border_colors2 = self.generate_hex2hex(
|
239
|
+
self.attributes.rest.border_color2, now["border_color2"], animation_steps
|
240
|
+
)
|
241
|
+
text_colors = self.generate_hex2hex(
|
242
|
+
self.attributes.rest.text_color, now["text_color"], animation_steps
|
243
|
+
)
|
244
|
+
import numpy as np
|
245
|
+
back_opacitys = np.linspace(
|
246
|
+
float(self.attributes.rest.back_opacity), float(now["back_opacity"]), animation_steps).tolist()
|
247
|
+
border_color_opacitys = np.linspace(
|
248
|
+
float(self.attributes.rest.border_color_opacity), float(now["border_color_opacity"]), animation_steps).tolist()
|
249
|
+
if self.attributes.rest.border_color2_opacity is None:
|
250
|
+
self.attributes.rest.border_color2_opacity = self.attributes.rest.border_color_opacity
|
251
|
+
if now["border_color2_opacity"] is None:
|
252
|
+
now["border_color2_opacity"] = now["border_color_opacity"]
|
253
|
+
border_color2_opacitys = np.linspace(
|
254
|
+
float(self.attributes.rest.border_color2_opacity), float(now["border_color2_opacity"]), animation_steps).tolist()
|
255
|
+
for i in range(animation_steps):
|
256
|
+
def update(ii=i):
|
257
|
+
from easydict import EasyDict
|
258
|
+
tempcolor = EasyDict(
|
259
|
+
{
|
260
|
+
"back_color": back_colors[ii],
|
261
|
+
"back_opacity": back_opacitys[ii],
|
262
|
+
"border_color": border_colors[ii],
|
263
|
+
"border_color_opacity": str(border_color_opacitys[ii]),
|
264
|
+
"border_color2": border_colors2[ii],
|
265
|
+
"border_color2_opacity": str(border_color2_opacitys[ii]),
|
266
|
+
"border_width": 1,
|
267
|
+
"text_color": text_colors[ii],
|
268
|
+
"radius": 6,
|
269
|
+
}
|
270
|
+
)
|
271
|
+
self._draw(None, tempcolor)
|
272
|
+
|
273
|
+
self.after(i * animation_step_time, update)
|
274
|
+
#self.after(animation_steps * animation_step_time + 10, lambda: self._draw(None, None))
|
275
|
+
|
192
276
|
self.dconfigure(
|
193
277
|
rest={
|
194
278
|
"back_color": r["back_color"],
|
tkflu/bwm.py
CHANGED
@@ -126,20 +126,25 @@ class BWm(FluGradient):
|
|
126
126
|
else:
|
127
127
|
self._light()
|
128
128
|
|
129
|
-
def _theme(self, mode):
|
129
|
+
def _theme(self, mode, animation_steps: int = None, animation_step_time: int = None):
|
130
130
|
from .designs.window import window
|
131
131
|
n = window(mode)
|
132
132
|
"""if self.attributes.back_color is not None:
|
133
133
|
n["back_color"] = self.attributes.back_color"""
|
134
|
-
|
134
|
+
if animation_steps is None:
|
135
|
+
from .designs.animation import get_animation_steps
|
136
|
+
animation_steps = get_animation_steps()
|
137
|
+
if animation_step_time is None:
|
138
|
+
from .designs.animation import get_animation_step_time
|
139
|
+
animation_step_time = get_animation_step_time()
|
135
140
|
if self.dcget("back_color"):
|
136
|
-
back_colors = self.generate_hex2hex(self.dcget("back_color"), n["back_color"], steps=
|
137
|
-
for i in range(
|
141
|
+
back_colors = self.generate_hex2hex(self.dcget("back_color"), n["back_color"], steps=animation_steps)
|
142
|
+
for i in range(animation_steps):
|
138
143
|
def update(ii=i): # 使用默认参数立即捕获i的值
|
139
144
|
self.dconfigure(back_color=back_colors[ii])
|
140
145
|
self._draw()
|
141
146
|
|
142
|
-
self.after(i *
|
147
|
+
self.after(i * animation_step_time, update) # 直接传递函数,不需要lambda
|
143
148
|
|
144
149
|
self.dconfigure(
|
145
150
|
back_color=n["back_color"],
|
tkflu/demos/designer.py
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
from tkflu import *
|
2
|
+
|
3
|
+
set_animation_steps(10)
|
4
|
+
set_animation_step_time(10)
|
5
|
+
|
6
|
+
root = FluWindow()
|
7
|
+
root.title("tkfluent designer")
|
8
|
+
root.geometry("500x300")
|
9
|
+
|
10
|
+
theme_manager = FluThemeManager(root)
|
11
|
+
|
12
|
+
menubar = FluMenuBar(root)
|
13
|
+
|
14
|
+
menu1 = FluMenu()
|
15
|
+
menu1.geometry("90x90")
|
16
|
+
menu1.add_command(label="Light", command=lambda: theme_manager.mode("light"))
|
17
|
+
menu1.add_command(label="Dark", command=lambda: theme_manager.mode("dark"))
|
18
|
+
|
19
|
+
def func1():
|
20
|
+
messagebox = FluToplevel()
|
21
|
+
messagebox.geometry("300x200")
|
22
|
+
|
23
|
+
label = FluLabel(messagebox, text="This is a example for tkfluent!", width=160, height=32)
|
24
|
+
label.pack(anchor="center")
|
25
|
+
|
26
|
+
menubar.add_command(label="File", style="standard", width=40, command=lambda: print("File -> Clicked"))
|
27
|
+
menubar.add_cascade(label="Theme Mode", style="standard", width=100, menu=menu1)
|
28
|
+
menubar.add_command(label="About", style="standard", width=40, command=lambda: func1())
|
29
|
+
|
30
|
+
menubar.show()
|
31
|
+
|
32
|
+
|
33
|
+
root.mainloop()
|
tkflu/demos/grad2.py
CHANGED
@@ -1,140 +1,17 @@
|
|
1
|
-
|
2
|
-
from tkinter import ttk
|
3
|
-
import numpy as np
|
1
|
+
from tkflu import *
|
4
2
|
|
3
|
+
set_animation_steps(20)
|
4
|
+
set_animation_step_time(50)
|
5
5
|
|
6
|
-
|
7
|
-
def __init__(self, root):
|
8
|
-
self.root = root
|
9
|
-
self.root.title("Tkinter渐变标签演示")
|
10
|
-
self.root.geometry("400x200")
|
6
|
+
root = FluWindow()
|
11
7
|
|
12
|
-
|
13
|
-
self.is_animating = False
|
14
|
-
self.current_step = 0
|
15
|
-
self.gradient_steps = 20 # 渐变步数
|
8
|
+
theme_manager = FluThemeManager(root)
|
16
9
|
|
17
|
-
|
18
|
-
self.create_widgets()
|
10
|
+
frame = FluFrame(root, mode="light", style="standard")
|
19
11
|
|
20
|
-
|
21
|
-
|
22
|
-
"#ffffff",
|
23
|
-
"#005fb8",
|
24
|
-
self.gradient_steps
|
25
|
-
)
|
12
|
+
btn = FluButton(frame, text="Button", mode="light", style="standard", command=lambda: theme_manager.toggle())
|
13
|
+
btn.pack(padx=20, pady=20, fill="both", expand="yes")
|
26
14
|
|
27
|
-
|
28
|
-
"""创建界面组件"""
|
29
|
-
# 渐变显示标签
|
30
|
-
self.label = tk.Label(
|
31
|
-
self.root,
|
32
|
-
text="渐变背景标签",
|
33
|
-
font=('Arial', 20),
|
34
|
-
relief='raised',
|
35
|
-
borderwidth=2
|
36
|
-
)
|
37
|
-
self.label.pack(pady=20, ipadx=50, ipady=30, fill='x', padx=20)
|
15
|
+
frame.pack(padx=20, pady=20, fill="both", expand="yes")
|
38
16
|
|
39
|
-
|
40
|
-
button_frame = ttk.Frame(self.root)
|
41
|
-
button_frame.pack(pady=10)
|
42
|
-
|
43
|
-
# 开始按钮
|
44
|
-
self.start_button = ttk.Button(
|
45
|
-
button_frame,
|
46
|
-
text="开始渐变",
|
47
|
-
command=self.toggle_animation
|
48
|
-
)
|
49
|
-
self.start_button.pack(side='left', padx=5)
|
50
|
-
|
51
|
-
# 重置按钮
|
52
|
-
ttk.Button(
|
53
|
-
button_frame,
|
54
|
-
text="重置",
|
55
|
-
command=self.reset_animation
|
56
|
-
).pack(side='left', padx=5)
|
57
|
-
|
58
|
-
def generate_gradient(self, start_color, end_color, steps):
|
59
|
-
"""生成颜色渐变序列"""
|
60
|
-
gradient = []
|
61
|
-
for t in np.linspace(0, 1, steps):
|
62
|
-
r = int(start_color[0] + (end_color[0] - start_color[0]) * t)
|
63
|
-
g = int(start_color[1] + (end_color[1] - start_color[1]) * t)
|
64
|
-
b = int(start_color[2] + (end_color[2] - start_color[2]) * t)
|
65
|
-
gradient.append(f"#{r:02x}{g:02x}{b:02x}")
|
66
|
-
return gradient
|
67
|
-
|
68
|
-
def generate_gradient_hex(self, start_hex, end_hex, steps):
|
69
|
-
"""
|
70
|
-
专为HEX颜色设计的渐变生成器
|
71
|
-
:param start_hex: 起始颜色 HEX格式 (如 "#FF0000")
|
72
|
-
:param end_hex: 结束颜色 HEX格式 (如 "#0000FF")
|
73
|
-
:param steps: 渐变步数
|
74
|
-
:return: HEX格式的颜色列表
|
75
|
-
"""
|
76
|
-
|
77
|
-
# 去除#号并转换为RGB元组
|
78
|
-
def hex_to_rgb(h):
|
79
|
-
h = h.lstrip('#')
|
80
|
-
return tuple(int(h[i:i + 2], 16) for i in (0, 2, 4))
|
81
|
-
|
82
|
-
# RGB转HEX
|
83
|
-
def rgb_to_hex(rgb):
|
84
|
-
return f"#{rgb[0]:02x}{rgb[1]:02x}{rgb[2]:02x}"
|
85
|
-
|
86
|
-
rgb_start = hex_to_rgb(start_hex)
|
87
|
-
rgb_end = hex_to_rgb(end_hex)
|
88
|
-
|
89
|
-
gradient = []
|
90
|
-
for t in np.linspace(0, 1, steps):
|
91
|
-
# 计算每个通道的中间值
|
92
|
-
r = int(rgb_start[0] + (rgb_end[0] - rgb_start[0]) * t)
|
93
|
-
g = int(rgb_start[1] + (rgb_end[1] - rgb_start[1]) * t)
|
94
|
-
b = int(rgb_start[2] + (rgb_end[2] - rgb_start[2]) * t)
|
95
|
-
|
96
|
-
# 确保值在0-255范围内并转换为HEX
|
97
|
-
gradient.append(rgb_to_hex((
|
98
|
-
max(0, min(255, r)),
|
99
|
-
max(0, min(255, g)),
|
100
|
-
max(0, min(255, b))
|
101
|
-
)))
|
102
|
-
|
103
|
-
return gradient
|
104
|
-
|
105
|
-
def toggle_animation(self):
|
106
|
-
"""切换动画状态"""
|
107
|
-
self.is_animating = not self.is_animating
|
108
|
-
self.start_button.config(
|
109
|
-
text="停止渐变" if self.is_animating else "开始渐变"
|
110
|
-
)
|
111
|
-
if self.is_animating:
|
112
|
-
self.animate_gradient()
|
113
|
-
|
114
|
-
def animate_gradient(self):
|
115
|
-
"""执行渐变动画"""
|
116
|
-
if not self.is_animating:
|
117
|
-
return
|
118
|
-
|
119
|
-
# 更新标签背景色
|
120
|
-
color = self.gradient[self.current_step]
|
121
|
-
self.label.config(background=color)
|
122
|
-
|
123
|
-
# 更新步进
|
124
|
-
self.current_step = (self.current_step + 1) % len(self.gradient)
|
125
|
-
|
126
|
-
# 50ms后继续下一帧 (约20FPS)
|
127
|
-
self.root.after(50, self.animate_gradient)
|
128
|
-
|
129
|
-
def reset_animation(self):
|
130
|
-
"""重置动画状态"""
|
131
|
-
self.is_animating = False
|
132
|
-
self.current_step = 0
|
133
|
-
self.start_button.config(text="开始渐变")
|
134
|
-
self.label.config(background='SystemButtonFace') # 恢复默认背景色
|
135
|
-
|
136
|
-
|
137
|
-
if __name__ == "__main__":
|
138
|
-
root = tk.Tk()
|
139
|
-
app = GradientLabelApp(root)
|
140
|
-
root.mainloop()
|
17
|
+
root.mainloop()
|
tkflu/demos/grad3.py
CHANGED
@@ -1,22 +1,16 @@
|
|
1
1
|
from tkflu import *
|
2
2
|
|
3
|
+
set_animation_steps(20)
|
4
|
+
set_animation_step_time(20)
|
3
5
|
|
4
6
|
root = FluWindow()
|
5
7
|
|
6
8
|
theme_manager = FluThemeManager(root)
|
7
9
|
|
8
|
-
|
9
|
-
|
10
|
-
menubar.show()
|
10
|
+
button = FluButton(root, text="Button", mode="light", style="standard", command=lambda: theme_manager.toggle())
|
11
|
+
button.pack(padx=20, pady=20, fill="both", expand="yes")
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
)
|
15
|
-
button.pack(padx=3, pady=3, )
|
16
|
-
|
17
|
-
button2 = FluToggleButton(
|
18
|
-
text="Toggle Button"
|
19
|
-
)
|
20
|
-
button2.pack(padx=3, pady=3, )
|
13
|
+
label = FluLabel(root, text="Label", mode="light")
|
14
|
+
label.pack(padx=20, pady=20, fill="both", expand="yes")
|
21
15
|
|
22
16
|
root.mainloop()
|
tkflu/designs/__init__.py
CHANGED
@@ -0,0 +1,37 @@
|
|
1
|
+
from os import environ
|
2
|
+
|
3
|
+
|
4
|
+
def set_animation_steps(steps: int):
|
5
|
+
environ["tkfluent.animation_steps"] = str(steps)
|
6
|
+
|
7
|
+
def get_animation_steps():
|
8
|
+
return int(environ["tkfluent.animation_steps"])
|
9
|
+
|
10
|
+
def set_animation_step_time(step_time: int):
|
11
|
+
environ["tkfluent.animation_step_time"] = str(step_time)
|
12
|
+
|
13
|
+
def get_animation_step_time():
|
14
|
+
return int(environ["tkfluent.animation_step_time"])
|
15
|
+
|
16
|
+
if "tkfluent.animation_steps" not in environ:
|
17
|
+
set_animation_steps(10)
|
18
|
+
if "tkfluent.animation_step_time" not in environ:
|
19
|
+
set_animation_step_time(10)
|
20
|
+
|
21
|
+
|
22
|
+
class FluAnimation(object):
|
23
|
+
def animation_steps(self, steps: int = None):
|
24
|
+
if steps:
|
25
|
+
from os import environ
|
26
|
+
environ["tkfluent.animation_steps"] = str(steps)
|
27
|
+
else:
|
28
|
+
from os import environ
|
29
|
+
return int(environ["tkfluent.animation_steps"])
|
30
|
+
|
31
|
+
def animation_step_time(self, step_time: int = None):
|
32
|
+
if step_time:
|
33
|
+
from os import environ
|
34
|
+
environ["tkfluent.animation_step_time"] = str(step_time)
|
35
|
+
else:
|
36
|
+
from os import environ
|
37
|
+
return int(environ["tkfluent.animation_step_time"])
|
tkflu/designs/gradient.py
CHANGED
tkflu/designs/label.py
ADDED
tkflu/designs/menubar.py
CHANGED
tkflu/designs/primary_color.py
CHANGED
@@ -1,16 +1,16 @@
|
|
1
|
+
from os import environ
|
2
|
+
|
3
|
+
|
1
4
|
def set_primary_color(color: tuple = None):
|
2
|
-
from os import environ
|
3
5
|
from json import dumps
|
4
6
|
environ["tkfluent.primary_color"] = dumps(color)
|
5
7
|
|
6
|
-
|
7
8
|
def get_primary_color():
|
8
|
-
from os import environ
|
9
9
|
from json import loads
|
10
10
|
return loads(environ["tkfluent.primary_color"])
|
11
11
|
|
12
|
-
|
13
|
-
set_primary_color(("#005fb8", "#60cdff"))
|
12
|
+
if "tkfluent.primary_color" not in environ:
|
13
|
+
set_primary_color(("#005fb8", "#60cdff"))
|
14
14
|
|
15
15
|
|
16
16
|
class FluPrimaryColor(object):
|
tkflu/frame.py
CHANGED
@@ -118,9 +118,10 @@ class FluFrameCanvas(DCanvas):
|
|
118
118
|
|
119
119
|
from tkinter import Frame
|
120
120
|
from tkdeft.object import DObject
|
121
|
+
from .designs.gradient import FluGradient
|
121
122
|
|
122
123
|
|
123
|
-
class FluFrame(Frame, DObject):
|
124
|
+
class FluFrame(Frame, DObject, FluGradient):
|
124
125
|
def __init__(self,
|
125
126
|
master=None,
|
126
127
|
*args,
|
@@ -179,8 +180,26 @@ class FluFrame(Frame, DObject):
|
|
179
180
|
else:
|
180
181
|
self._light()
|
181
182
|
|
182
|
-
def _theme(self, mode, style):
|
183
|
+
def _theme(self, mode, style, animation_steps: int = None, animation_step_time: int = None):
|
183
184
|
n = frame(mode, style)
|
185
|
+
|
186
|
+
if animation_steps is None:
|
187
|
+
from .designs.animation import get_animation_steps
|
188
|
+
animation_steps = get_animation_steps()
|
189
|
+
if animation_step_time is None:
|
190
|
+
from .designs.animation import get_animation_step_time
|
191
|
+
animation_step_time = get_animation_step_time()
|
192
|
+
|
193
|
+
if hasattr(self.attributes, "back_color") and hasattr(n, "back_color"):
|
194
|
+
back_colors = self.generate_hex2hex(self.attributes.back_color, n["back_color"], steps=animation_steps)
|
195
|
+
for i in range(animation_steps):
|
196
|
+
def update(ii=i): # 使用默认参数立即捕获i的值
|
197
|
+
print(back_colors[ii])
|
198
|
+
self._draw(tempcolor=back_colors[ii])
|
199
|
+
self.update()
|
200
|
+
|
201
|
+
self.after(i * animation_step_time, update) # 直接传递函数,不需要lambda
|
202
|
+
self.after(animation_steps * animation_step_time + 10, lambda: self._draw())
|
184
203
|
self.dconfigure(
|
185
204
|
back_color=n["back_color"],
|
186
205
|
border_color=n["border_color"],
|
@@ -189,6 +208,7 @@ class FluFrame(Frame, DObject):
|
|
189
208
|
radius=n["radius"],
|
190
209
|
)
|
191
210
|
self._draw()
|
211
|
+
self.update()
|
192
212
|
self.canvas.update()
|
193
213
|
|
194
214
|
def _light(self):
|
@@ -271,11 +291,14 @@ class FluFrame(Frame, DObject):
|
|
271
291
|
|
272
292
|
place = place_configure
|
273
293
|
|
274
|
-
def _draw(self, event=None):
|
294
|
+
def _draw(self, event=None, tempcolor: dict = None):
|
275
295
|
|
276
296
|
self.canvas.delete("all")
|
277
297
|
self.canvas.config(background=self.canvas.master.cget("background"))
|
278
|
-
|
298
|
+
if not tempcolor:
|
299
|
+
_back_color = self.attributes.back_color
|
300
|
+
else:
|
301
|
+
_back_color = tempcolor
|
279
302
|
#_back_opacity = self.attributes.back_opacity
|
280
303
|
_border_color = self.attributes.border_color
|
281
304
|
_border_color_opacity = self.attributes.border_color_opacity
|
@@ -297,5 +320,10 @@ class FluFrame(Frame, DObject):
|
|
297
320
|
height=self.canvas.winfo_height() - _border_width * 2 - _radius
|
298
321
|
)
|
299
322
|
|
323
|
+
self.update()
|
324
|
+
|
325
|
+
self.after(100, lambda: self.update())
|
326
|
+
self.after(100, lambda: self.config(background=_back_color))
|
327
|
+
|
300
328
|
def _event_configure(self, event=None):
|
301
329
|
self._draw(event)
|