tkfluent 0.0.9__py3-none-any.whl → 0.1.1__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 +2 -5
- tkflu/badge.py +2 -0
- tkflu/button.py +97 -20
- tkflu/bwm.py +14 -1
- tkflu/demos/demo1.py +8 -0
- tkflu/demos/grad.py +70 -0
- tkflu/demos/grad2.py +140 -0
- tkflu/demos/grad3.py +11 -0
- tkflu/demos/test.py +8 -0
- tkflu/demos/tooltip.py +1 -1
- tkflu/designs/gradient.py +54 -0
- tkflu/designs/menubar.py +13 -0
- tkflu/frame.py +19 -4
- tkflu/menu.py +1 -1
- tkflu/menubar.py +34 -12
- tkflu/thememanager.py +35 -2
- tkflu/togglebutton.py +125 -32
- tkflu/tooltip.py +2 -2
- tkfluent-0.1.1.dist-info/METADATA +323 -0
- {tkfluent-0.0.9.dist-info → tkfluent-0.1.1.dist-info}/RECORD +21 -14
- tkfluent-0.0.9.dist-info/METADATA +0 -82
- {tkfluent-0.0.9.dist-info → tkfluent-0.1.1.dist-info}/WHEEL +0 -0
tkflu/__main__.py
CHANGED
@@ -103,9 +103,6 @@ togglebutton3.pack(fill="x", padx=5, pady=5)
|
|
103
103
|
entry1 = FluEntry(frame)
|
104
104
|
entry1.pack(fill="x", padx=5, pady=5)
|
105
105
|
|
106
|
-
entry2 = FluEntry(frame, height=50)
|
107
|
-
entry2.pack(fill="x", padx=5, pady=5)
|
108
|
-
|
109
106
|
text1 = FluText(frame)
|
110
107
|
text1.pack(fill="x", padx=5, pady=5)
|
111
108
|
|
@@ -116,6 +113,6 @@ slider1.pack(fill="x", padx=5, pady=5)
|
|
116
113
|
listbox1.dconfigure()
|
117
114
|
listbox1.pack(fill="x", padx=5, pady=5)"""
|
118
115
|
|
119
|
-
frame.pack(fill="both", expand="yes", side="right", padx=
|
120
|
-
|
116
|
+
frame.pack(fill="both", expand="yes", side="right", padx=15, pady=15)
|
117
|
+
frame.update_idletasks()
|
121
118
|
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,71 @@ 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, animate_steps: int = 10):
|
188
205
|
r = button(mode, style, "rest")
|
189
206
|
h = button(mode, style, "hover")
|
190
207
|
p = button(mode, style, "pressed")
|
191
208
|
d = button(mode, style, "disabled")
|
209
|
+
steps = animate_steps
|
210
|
+
if self.dcget("state") == "normal":
|
211
|
+
if self.enter:
|
212
|
+
if self.button1:
|
213
|
+
now = p
|
214
|
+
else:
|
215
|
+
now = h
|
216
|
+
else:
|
217
|
+
now = r
|
218
|
+
else:
|
219
|
+
now = d
|
220
|
+
if hasattr(self.attributes.rest, "back_color"):
|
221
|
+
back_colors = self.generate_hex2hex(
|
222
|
+
self.attributes.rest.back_color, now["back_color"], steps
|
223
|
+
)
|
224
|
+
border_colors = self.generate_hex2hex(
|
225
|
+
self.attributes.rest.border_color, now["border_color"], steps
|
226
|
+
)
|
227
|
+
if self.attributes.rest.border_color2 is None:
|
228
|
+
self.attributes.rest.border_color2 = self.attributes.rest.border_color
|
229
|
+
if now["border_color2"] is None:
|
230
|
+
now["border_color2"] = now["border_color"]
|
231
|
+
border_colors2 = self.generate_hex2hex(
|
232
|
+
self.attributes.rest.border_color2, now["border_color2"], steps
|
233
|
+
)
|
234
|
+
text_colors = self.generate_hex2hex(
|
235
|
+
self.attributes.rest.text_color, now["text_color"], steps
|
236
|
+
)
|
237
|
+
import numpy as np
|
238
|
+
back_opacitys = np.linspace(
|
239
|
+
float(self.attributes.rest.back_opacity), float(now["back_opacity"]), steps).tolist()
|
240
|
+
border_color_opacitys = np.linspace(
|
241
|
+
float(self.attributes.rest.border_color_opacity), float(now["border_color_opacity"]), steps).tolist()
|
242
|
+
if self.attributes.rest.border_color2_opacity is None:
|
243
|
+
self.attributes.rest.border_color2_opacity = self.attributes.rest.border_color_opacity
|
244
|
+
if now["border_color2_opacity"] is None:
|
245
|
+
now["border_color2_opacity"] = now["border_color_opacity"]
|
246
|
+
border_color2_opacitys = np.linspace(
|
247
|
+
float(self.attributes.rest.border_color2_opacity), float(now["border_color2_opacity"]), steps).tolist()
|
248
|
+
for i in range(steps):
|
249
|
+
def update(ii=i):
|
250
|
+
from easydict import EasyDict
|
251
|
+
tempcolor = EasyDict(
|
252
|
+
{
|
253
|
+
"back_color": back_colors[ii],
|
254
|
+
"back_opacity": back_opacitys[ii],
|
255
|
+
"border_color": border_colors[ii],
|
256
|
+
"border_color_opacity": str(border_color_opacitys[ii]),
|
257
|
+
"border_color2": border_colors2[ii],
|
258
|
+
"border_color2_opacity": str(border_color2_opacitys[ii]),
|
259
|
+
"border_width": 1,
|
260
|
+
"text_color": text_colors[ii],
|
261
|
+
"radius": 6,
|
262
|
+
}
|
263
|
+
)
|
264
|
+
self._draw(None, tempcolor)
|
265
|
+
|
266
|
+
self.after(i * 10, update)
|
267
|
+
self.after(steps * 10 + 10, lambda: self._draw(None, None))
|
268
|
+
|
192
269
|
self.dconfigure(
|
193
270
|
rest={
|
194
271
|
"back_color": r["back_color"],
|
tkflu/bwm.py
CHANGED
@@ -1,4 +1,7 @@
|
|
1
|
-
|
1
|
+
from .designs.gradient import FluGradient
|
2
|
+
|
3
|
+
|
4
|
+
class BWm(FluGradient):
|
2
5
|
def _draw(self, event=None):
|
3
6
|
|
4
7
|
"""
|
@@ -128,6 +131,16 @@ class BWm(object):
|
|
128
131
|
n = window(mode)
|
129
132
|
"""if self.attributes.back_color is not None:
|
130
133
|
n["back_color"] = self.attributes.back_color"""
|
134
|
+
|
135
|
+
if self.dcget("back_color"):
|
136
|
+
back_colors = self.generate_hex2hex(self.dcget("back_color"), n["back_color"], steps=10)
|
137
|
+
for i in range(10):
|
138
|
+
def update(ii=i): # 使用默认参数立即捕获i的值
|
139
|
+
self.dconfigure(back_color=back_colors[ii])
|
140
|
+
self._draw()
|
141
|
+
|
142
|
+
self.after(i * 10, update) # 直接传递函数,不需要lambda
|
143
|
+
|
131
144
|
self.dconfigure(
|
132
145
|
back_color=n["back_color"],
|
133
146
|
text_color=n["text_color"],
|
tkflu/demos/demo1.py
ADDED
tkflu/demos/grad.py
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
import matplotlib.pyplot as plt
|
2
|
+
import numpy as np
|
3
|
+
|
4
|
+
|
5
|
+
def color_gradient(color1, color2, steps=10, output_format='both'):
|
6
|
+
"""
|
7
|
+
生成颜色渐变序列
|
8
|
+
:param color1: 起始颜色 (RGB元组或HEX字符串)
|
9
|
+
:param color2: 结束颜色 (RGB元组或HEX字符串)
|
10
|
+
:param steps: 渐变步数
|
11
|
+
:param output_format: 输出格式 ('rgb', 'hex' 或 'both')
|
12
|
+
:return: 渐变颜色列表
|
13
|
+
"""
|
14
|
+
|
15
|
+
# 输入格式处理
|
16
|
+
def parse_color(color):
|
17
|
+
if isinstance(color, str): # HEX格式
|
18
|
+
color = color.lstrip('#')
|
19
|
+
return tuple(int(color[i:i + 2], 16) for i in (0, 2, 4))
|
20
|
+
return color # 已经是RGB格式
|
21
|
+
|
22
|
+
rgb1 = np.array(parse_color(color1))
|
23
|
+
rgb2 = np.array(parse_color(color2))
|
24
|
+
|
25
|
+
# 生成渐变
|
26
|
+
gradient = []
|
27
|
+
for t in np.linspace(0, 1, steps):
|
28
|
+
rgb = rgb1 + (rgb2 - rgb1) * t
|
29
|
+
rgb = np.round(rgb).astype(int)
|
30
|
+
rgb_clipped = np.clip(rgb, 0, 255) # 确保在0-255范围内
|
31
|
+
gradient.append(rgb_clipped)
|
32
|
+
|
33
|
+
# 格式转换
|
34
|
+
result = []
|
35
|
+
for color in gradient:
|
36
|
+
r, g, b = color
|
37
|
+
if output_format == 'rgb':
|
38
|
+
result.append(tuple(color))
|
39
|
+
elif output_format == 'hex':
|
40
|
+
result.append(f"#{r:02x}{g:02x}{b:02x}")
|
41
|
+
else: # both
|
42
|
+
result.append({
|
43
|
+
'rgb': tuple(color),
|
44
|
+
'hex': f"#{r:02x}{g:02x}{b:02x}"
|
45
|
+
})
|
46
|
+
|
47
|
+
return result
|
48
|
+
|
49
|
+
|
50
|
+
# 示例使用
|
51
|
+
if __name__ == "__main__":
|
52
|
+
# 输入颜色 (支持RGB或HEX)
|
53
|
+
start_color = "#FF0000" # 红色
|
54
|
+
end_color = (0, 0, 255) # 蓝色
|
55
|
+
|
56
|
+
# 生成渐变 (20个步骤)
|
57
|
+
gradient = color_gradient(start_color, end_color, steps=20, output_format='both')
|
58
|
+
|
59
|
+
# 打印输出
|
60
|
+
print("颜色渐变序列:")
|
61
|
+
for i, color in enumerate(gradient):
|
62
|
+
print(f"{i + 1:2d}: RGB{color['rgb']} -> {color['hex']}")
|
63
|
+
|
64
|
+
# 可视化展示
|
65
|
+
plt.figure(figsize=(10, 2))
|
66
|
+
for i, color in enumerate(gradient):
|
67
|
+
plt.fill_between([i, i + 1], 0, 1, color=np.array(color['rgb']) / 255)
|
68
|
+
plt.title("Color Gradient Visualization")
|
69
|
+
plt.axis('off')
|
70
|
+
plt.show()
|
tkflu/demos/grad2.py
ADDED
@@ -0,0 +1,140 @@
|
|
1
|
+
import tkinter as tk
|
2
|
+
from tkinter import ttk
|
3
|
+
import numpy as np
|
4
|
+
|
5
|
+
|
6
|
+
class GradientLabelApp:
|
7
|
+
def __init__(self, root):
|
8
|
+
self.root = root
|
9
|
+
self.root.title("Tkinter渐变标签演示")
|
10
|
+
self.root.geometry("400x200")
|
11
|
+
|
12
|
+
# 渐变控制变量
|
13
|
+
self.is_animating = False
|
14
|
+
self.current_step = 0
|
15
|
+
self.gradient_steps = 20 # 渐变步数
|
16
|
+
|
17
|
+
# 创建UI组件
|
18
|
+
self.create_widgets()
|
19
|
+
|
20
|
+
# 预生成渐变序列 (从蓝色到红色)
|
21
|
+
self.gradient = self.generate_gradient_hex(
|
22
|
+
"#ffffff",
|
23
|
+
"#005fb8",
|
24
|
+
self.gradient_steps
|
25
|
+
)
|
26
|
+
|
27
|
+
def create_widgets(self):
|
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)
|
38
|
+
|
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()
|
tkflu/demos/grad3.py
ADDED
tkflu/demos/test.py
ADDED
tkflu/demos/tooltip.py
CHANGED
@@ -0,0 +1,54 @@
|
|
1
|
+
class FluGradient:
|
2
|
+
def hex_to_rgb(self, h: str):
|
3
|
+
h = h.lstrip('#')
|
4
|
+
return tuple(int(h[i:i + 2], 16) for i in (0, 2, 4))
|
5
|
+
|
6
|
+
def rgb_to_hex(self, rgb):
|
7
|
+
return f"#{rgb[0]:02x}{rgb[1]:02x}{rgb[2]:02x}"
|
8
|
+
|
9
|
+
def generate_rgb2hex(self, start_color, end_color, steps):
|
10
|
+
"""生成颜色渐变序列"""
|
11
|
+
import numpy as np
|
12
|
+
gradient = []
|
13
|
+
for t in np.linspace(0, 1, steps):
|
14
|
+
r = int(start_color[0] + (end_color[0] - start_color[0]) * t)
|
15
|
+
g = int(start_color[1] + (end_color[1] - start_color[1]) * t)
|
16
|
+
b = int(start_color[2] + (end_color[2] - start_color[2]) * t)
|
17
|
+
gradient.append(f"#{r:02x}{g:02x}{b:02x}")
|
18
|
+
return gradient
|
19
|
+
|
20
|
+
def generate_hex2hex(self, start_hex, end_hex, steps):
|
21
|
+
"""
|
22
|
+
专为HEX颜色设计的渐变生成器
|
23
|
+
:param start_hex: 起始颜色 HEX格式 (如 "#FF0000")
|
24
|
+
:param end_hex: 结束颜色 HEX格式 (如 "#0000FF")
|
25
|
+
:param steps: 渐变步数
|
26
|
+
:return: HEX格式的颜色列表
|
27
|
+
"""
|
28
|
+
|
29
|
+
# 去除#号并转换为RGB元组
|
30
|
+
|
31
|
+
# RGB转HEX
|
32
|
+
|
33
|
+
rgb_start = self.hex_to_rgb(start_hex)
|
34
|
+
rgb_end = self.hex_to_rgb(end_hex)
|
35
|
+
import numpy as np
|
36
|
+
gradient = []
|
37
|
+
for t in np.linspace(0, 1, steps):
|
38
|
+
# 计算每个通道的中间值
|
39
|
+
r = int(rgb_start[0] + (rgb_end[0] - rgb_start[0]) * t)
|
40
|
+
g = int(rgb_start[1] + (rgb_end[1] - rgb_start[1]) * t)
|
41
|
+
b = int(rgb_start[2] + (rgb_end[2] - rgb_start[2]) * t)
|
42
|
+
|
43
|
+
# 确保值在0-255范围内并转换为HEX
|
44
|
+
gradient.append(
|
45
|
+
self.rgb_to_hex(
|
46
|
+
(
|
47
|
+
max(0, min(255, r)),
|
48
|
+
max(0, min(255, g)),
|
49
|
+
max(0, min(255, b))
|
50
|
+
)
|
51
|
+
)
|
52
|
+
)
|
53
|
+
|
54
|
+
return gradient
|
tkflu/designs/menubar.py
ADDED
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,16 @@ 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, animate_steps: int = 10):
|
183
184
|
n = frame(mode, style)
|
185
|
+
if hasattr(self.attributes, "back_color") and hasattr(n, "back_color"):
|
186
|
+
back_colors = self.generate_hex2hex(self.attributes.back_color, n["back_color"], steps=10)
|
187
|
+
for i in range(10):
|
188
|
+
def update(ii=i): # 使用默认参数立即捕获i的值
|
189
|
+
self._draw(tempcolor=back_colors[ii])
|
190
|
+
|
191
|
+
self.after(i * 10, update) # 直接传递函数,不需要lambda
|
192
|
+
self.after(animate_steps * 10 + 50, lambda: self.update())
|
184
193
|
self.dconfigure(
|
185
194
|
back_color=n["back_color"],
|
186
195
|
border_color=n["border_color"],
|
@@ -188,6 +197,9 @@ class FluFrame(Frame, DObject):
|
|
188
197
|
border_width=n["border_width"],
|
189
198
|
radius=n["radius"],
|
190
199
|
)
|
200
|
+
self._draw()
|
201
|
+
self.update()
|
202
|
+
self.canvas.update()
|
191
203
|
|
192
204
|
def _light(self):
|
193
205
|
self._theme("light", "standard")
|
@@ -269,11 +281,14 @@ class FluFrame(Frame, DObject):
|
|
269
281
|
|
270
282
|
place = place_configure
|
271
283
|
|
272
|
-
def _draw(self, event=None):
|
284
|
+
def _draw(self, event=None, tempcolor: dict = None):
|
273
285
|
|
274
286
|
self.canvas.delete("all")
|
275
287
|
self.canvas.config(background=self.canvas.master.cget("background"))
|
276
|
-
|
288
|
+
if not tempcolor:
|
289
|
+
_back_color = self.attributes.back_color
|
290
|
+
else:
|
291
|
+
_back_color = tempcolor
|
277
292
|
#_back_opacity = self.attributes.back_opacity
|
278
293
|
_border_color = self.attributes.border_color
|
279
294
|
_border_color_opacity = self.attributes.border_color_opacity
|
tkflu/menu.py
CHANGED