tkfluent 0.1.1__py3-none-any.whl → 0.1.3__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/designs/__init__.py CHANGED
@@ -1,2 +1,3 @@
1
1
  from .design import FluDesign
2
2
  from .primary_color import FluPrimaryColor, set_primary_color, get_primary_color
3
+ from .animation import FluAnimation, set_animation_steps, set_animation_step_time, get_animation_steps, get_animation_step_time
@@ -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
@@ -34,6 +34,8 @@ class FluGradient:
34
34
  rgb_end = self.hex_to_rgb(end_hex)
35
35
  import numpy as np
36
36
  gradient = []
37
+ if steps is None:
38
+ return None
37
39
  for t in np.linspace(0, 1, steps):
38
40
  # 计算每个通道的中间值
39
41
  r = int(rgb_start[0] + (rgb_end[0] - rgb_start[0]) * t)
tkflu/designs/label.py ADDED
@@ -0,0 +1,10 @@
1
+ def label(mode: str):
2
+ mode = mode.lower()
3
+ if mode == "light":
4
+ return {
5
+ "text_color": "#000000",
6
+ }
7
+ else:
8
+ return {
9
+ "text_color": "#ffffff",
10
+ }
tkflu/designs/menubar.py CHANGED
@@ -1,6 +1,3 @@
1
- from .primary_color import get_primary_color
2
-
3
-
4
1
  def menubar(mode):
5
2
  mode = mode.lower()
6
3
  if mode == "light":
@@ -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
@@ -180,16 +180,26 @@ class FluFrame(Frame, DObject, FluGradient):
180
180
  else:
181
181
  self._light()
182
182
 
183
- def _theme(self, mode, style, animate_steps: int = 10):
183
+ def _theme(self, mode, style, animation_steps: int = None, animation_step_time: int = None):
184
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())
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
+ if not animation_steps == 0 or not animation_step_time == 0:
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())
193
203
  self.dconfigure(
194
204
  back_color=n["back_color"],
195
205
  border_color=n["border_color"],
@@ -310,5 +320,10 @@ class FluFrame(Frame, DObject, FluGradient):
310
320
  height=self.canvas.winfo_height() - _border_width * 2 - _radius
311
321
  )
312
322
 
323
+ self.update()
324
+
325
+ self.after(100, lambda: self.update())
326
+ self.after(100, lambda: self.config(background=_back_color))
327
+
313
328
  def _event_configure(self, event=None):
314
329
  self._draw(event)
tkflu/image.py CHANGED
@@ -0,0 +1,4 @@
1
+ from .frame import FluFrame
2
+
3
+
4
+ class FluImage(FluFrame):
tkflu/label.py CHANGED
@@ -1,8 +1,9 @@
1
1
  from tkdeft.windows.drawwidget import DDrawWidget
2
2
  from .tooltip import FluToolTipBase
3
+ from .designs.gradient import FluGradient
3
4
 
4
5
 
5
- class FluLabel(DDrawWidget, FluToolTipBase):
6
+ class FluLabel(DDrawWidget, FluToolTipBase, FluGradient):
6
7
  def __init__(self, *args,
7
8
  text="",
8
9
  width=120,
@@ -37,29 +38,43 @@ class FluLabel(DDrawWidget, FluToolTipBase):
37
38
 
38
39
  self.theme(mode=mode)
39
40
 
40
- def _draw(self, event=None):
41
+ def _draw(self, event=None, tempcolor=None):
41
42
  super()._draw(event)
42
43
 
43
- self.delete("all")
44
-
45
- self.element_text = self.create_text(
46
- self.winfo_width() / 2, self.winfo_height() / 2, anchor="center",
47
- fill=self.attributes.text_color, text=self.attributes.text, font=self.attributes.font
48
- )
44
+ if tempcolor:
45
+ _text_color = tempcolor
46
+ else:
47
+ _text_color = self.attributes.text_color
49
48
 
50
- def theme(self, mode="light"):
51
- self.mode = mode
52
- if mode.lower() == "dark":
53
- self._dark()
49
+ if not hasattr(self, "element_text"):
50
+ self.element_text = self.create_text(
51
+ self.winfo_width() / 2, self.winfo_height() / 2, anchor="center",
52
+ fill=_text_color, text=self.attributes.text, font=self.attributes.font
53
+ )
54
54
  else:
55
- self._light()
55
+ self.coords(self.element_text, self.winfo_width() / 2, self.winfo_height() / 2)
56
+ self.itemconfigure(self.element_text, fill=_text_color, text=self.attributes.text, font=self.attributes.font)
56
57
 
57
- def _light(self):
58
+ def theme(self, mode="light", animation_steps: int = None, animation_step_time: int = None):
59
+ from .designs.label import label
60
+ self.mode = mode
61
+ m = label(mode)
62
+
63
+ if animation_steps is None:
64
+ from .designs.animation import get_animation_steps
65
+ animation_steps = get_animation_steps()
66
+ if animation_step_time is None:
67
+ from .designs.animation import get_animation_step_time
68
+ animation_step_time = get_animation_step_time()
69
+
70
+ if hasattr(self, "tk"):
71
+ if self.attributes.text_color != m["text_color"]:
72
+ text_colors = self.generate_hex2hex(self.attributes.text_color, m["text_color"], steps=animation_steps)
73
+ for i in range(animation_steps):
74
+ def update(ii=i): # 使用默认参数立即捕获i的值
75
+ self._draw(tempcolor=text_colors[ii])
76
+
77
+ self.after(i * animation_step_time, update) # 直接传递函数,不需要lambda
58
78
  self.dconfigure(
59
- text_color="#000000"
79
+ text_color=m["text_color"]
60
80
  )
61
-
62
- def _dark(self):
63
- self.dconfigure(
64
- text_color="#ffffff"
65
- )
tkflu/menu.py CHANGED
@@ -88,7 +88,7 @@ class FluMenu(FluPopupMenu, FluToolTipBase):
88
88
  def command(event=None):
89
89
  #print(menu._w)
90
90
 
91
- menu.popup(widget.winfo_rootx()+widget.winfo_width()+100, widget.winfo_rooty())
91
+ menu.popup(widget.winfo_rootx()+widget.winfo_width()+self.winfo_width(), widget.winfo_rooty())
92
92
  menu.window.deiconify()
93
93
  menu.window.attributes("-topmost")
94
94
 
tkflu/menubar.py CHANGED
@@ -130,30 +130,42 @@ class FluMenuBar(Frame, DObject, FluGradient):
130
130
  widget._draw()
131
131
  widget.update()
132
132
 
133
- def theme_myself(self, mode="light", animate_steps: int = 10):
133
+ def theme_myself(self, mode="light", animation_steps: int = None, animation_step_time: int = None):
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()
134
140
  from .designs.menubar import menubar
135
141
  m = menubar(mode)
136
142
  self.mode = mode
137
- if mode.lower() == "dark":
138
- if hasattr(self, "tk"):
139
- back_colors = self.generate_hex2hex(self.attributes.back_color, m["back_color"], steps=10)
140
- for i in range(10):
141
- def update(ii=i): # 使用默认参数立即捕获i的值
142
- self.dconfigure(back_color=back_colors[ii])
143
- self._draw()
144
-
145
- self.after(i * 10, update) # 直接传递函数,不需要lambda
146
- self.after(animate_steps*10+50, lambda: self.update_children())
147
- else:
148
- if hasattr(self, "tk"):
149
- back_colors = self.generate_hex2hex(self.attributes.back_color, m["back_color"], steps=10)
150
- for i in range(10):
151
- def update(ii=i): # 使用默认参数立即捕获i的值
152
- self.dconfigure(back_color=back_colors[ii])
153
- self._draw()
154
-
155
- self.after(i * 20, update) # 直接传递函数,不需要lambda
156
-
143
+ if hasattr(self, "tk"):
144
+ if not animation_steps == 0 or not animation_step_time == 0:
145
+ if mode.lower() == "dark":
146
+ back_colors = self.generate_hex2hex(self.attributes.back_color, m["back_color"], steps=animation_steps)
147
+ for i in range(animation_steps):
148
+ def update(ii=i): # 使用默认参数立即捕获i的值
149
+ self.dconfigure(back_color=back_colors[ii])
150
+ self._draw()
151
+
152
+ self.after(i * animation_step_time, update) # 直接传递函数,不需要lambda
153
+ else:
154
+ back_colors = self.generate_hex2hex(self.attributes.back_color, m["back_color"], steps=animation_steps)
155
+ for i in range(animation_steps):
156
+ def update(ii=i): # 使用默认参数立即捕获i的值
157
+ self.dconfigure(back_color=back_colors[ii])
158
+ self._draw()
159
+
160
+ self.after(i * animation_step_time, update) # 直接传递函数,不需要lambda
161
+
162
+ self.after(animation_steps * animation_step_time + 50, lambda: self.update_children())
163
+ else:
164
+ if mode.lower() == "dark":
165
+ self.dconfigure(back_color=m["back_color"])
166
+ else:
167
+ self.dconfigure(back_color=m["back_color"])
168
+ self._draw()
157
169
 
158
170
  def _draw(self, event=None):
159
171
  self.config(background=self.attributes.back_color)
tkflu/text.py CHANGED
@@ -172,6 +172,8 @@ class FluText(FluTextCanvas, DDrawWidget, FluToolTipBase):
172
172
  height=self.winfo_height() - _border_width * 2 - _radius
173
173
  )
174
174
 
175
+ if hasattr(self, "element_border"):
176
+ self.delete(self.element_border)
175
177
  self.element_border = self.create_round_rectangle(
176
178
  0, 0, width, height, _radius, temppath=self.temppath,
177
179
  fill=_back_color, fill_opacity=_back_opacity, stop1=_stop1, stop2=_stop2,
@@ -179,20 +181,50 @@ class FluText(FluTextCanvas, DDrawWidget, FluToolTipBase):
179
181
  outline2_opacity=_border_color2_opacity,
180
182
  width=_border_width
181
183
  )
182
-
184
+ """if _underline_fill:
185
+ if not hasattr(self, "element_line"):
186
+ self.element_line = self.create_line(
187
+ _radius / 3 + _border_width, self.winfo_height() - _radius / 3,
188
+ self.winfo_width() - _radius / 3 - _border_width * 2, self.winfo_height() - _radius / 3,
189
+ width=_underline_width, fill=_underline_fill
190
+ )
191
+ else:
192
+ self.coords(
193
+ self.element_line, _radius / 3 + _border_width, self.winfo_height() - _radius / 3,
194
+ self.winfo_width() - _radius / 3 - _border_width * 2, self.winfo_height() - _radius / 3,
195
+ )
196
+ self.itemconfigure(self.element_line, width=_underline_width, fill=_underline_fill)
197
+ """
198
+ if hasattr(self, "element_line"):
199
+ self.delete(self.element_line)
183
200
  if _underline_fill:
184
201
  self.element_line = self.create_line(
185
202
  _radius / 3 + _border_width, self.winfo_height() - _radius / 3,
186
203
  self.winfo_width() - _radius / 3 - _border_width * 2, self.winfo_height() - _radius / 3,
187
204
  width=_underline_width, fill=_underline_fill
188
205
  )
189
-
206
+ """
207
+ if not hasattr(self, "element_text"):
208
+ self.element_text = self.create_window(
209
+ self.winfo_width() / 2, self.winfo_height() / 2,
210
+ window=self.text,
211
+ width=self.winfo_width() - _border_width * 2 - _radius,
212
+ height=self.winfo_height() - _border_width * 2 - _radius
213
+ )
214
+ else:
215
+ self.coords(self.element_text, self.winfo_width() / 2, self.winfo_height() / 2,
216
+ self.winfo_width() - _border_width * 2 - _radius, self.winfo_height() - _border_width * 2 - _radius)
217
+ """
218
+ if hasattr(self, "element_text"):
219
+ self.delete(self.element_text)
190
220
  self.element_text = self.create_window(
191
221
  self.winfo_width() / 2, self.winfo_height() / 2,
192
222
  window=self.text,
193
223
  width=self.winfo_width() - _border_width * 2 - _radius,
194
224
  height=self.winfo_height() - _border_width * 2 - _radius
195
225
  )
226
+ self.tag_raise(self.element_text, self.element_border)
227
+ self.tag_raise(self.element_line, self.element_border)
196
228
 
197
229
  #self.tag_raise(self.element_text)
198
230
 
tkflu/thememanager.py CHANGED
@@ -1,9 +1,10 @@
1
1
  from .window import FluWindow
2
2
  from .toplevel import FluToplevel
3
+ from typing import Union
3
4
 
4
5
 
5
6
  class FluThemeManager(object):
6
- def __init__(self, window=None, mode: str = "light", delay: int or None = 100):
7
+ def __init__(self, window=None, mode: str = "light", delay: Union[int, None] = 100):
7
8
  if window:
8
9
  self._window = window
9
10
  else:
@@ -13,7 +14,7 @@ class FluThemeManager(object):
13
14
  self.mode(self._mode)
14
15
  self._window.after(delay, lambda: self.mode(self._mode))
15
16
 
16
- def mode(self, mode: str, delay: int or None = 0):
17
+ def mode(self, mode: str, delay: Union[int, None] = 50):
17
18
  def _():
18
19
  self._mode = mode
19
20
  if hasattr(self._window, "theme"):
@@ -40,27 +41,12 @@ class FluThemeManager(object):
40
41
  if hasattr(widget, "update_children"):
41
42
  widget.update_children()
42
43
  widget.update()
43
- #self._window.after(delay+300, __)
44
+ #print(len(self._window.winfo_children()))
45
+ self._window.after(delay+len(self._window.winfo_children()), __)
44
46
 
45
- def toggle(self, delay: int or None = None):
47
+ def toggle(self, delay: Union[int, None] = None):
46
48
  if self._mode == "light":
47
49
  mode = "dark"
48
50
  else:
49
51
  mode = "light"
50
- def _():
51
- self._mode = mode
52
- if hasattr(self._window, "theme"):
53
- self._window.theme(mode=mode)
54
- if hasattr(self._window, "_draw"):
55
- self._window._draw()
56
- self._window.update()
57
- for widget in self._window.winfo_children():
58
- if hasattr(widget, "theme"):
59
- widget.theme(mode=mode)
60
- if hasattr(widget, "_draw"):
61
- widget._draw()
62
- widget.update()
63
- if delay:
64
- self._window.after(delay, _)
65
- else:
66
- _()
52
+ self.mode(mode)
tkflu/togglebutton.py CHANGED
@@ -391,90 +391,89 @@ class FluToggleButton(FluToggleButtonCanvas, DDrawWidget, FluToolTipBase, FluGra
391
391
  def invoke(self):
392
392
  self.attributes.command()
393
393
 
394
- def toggle(self, animate_steps: int = 10):
395
- """
396
-
397
- "back_color": "#ffffff",
398
- "back_opacity": "0.7",
399
- "border_color": "#000000",
400
- "border_color_opacity": "0.2",
401
- "border_color2": "#000000",
402
- "border_color2_opacity": "0.3",
403
- "border_width": 1,
404
- "radius": 6,
405
- "text_color": "#000000",
406
- :return:
407
- """
408
- steps = animate_steps
394
+ def toggle(self, animation_steps: int = None, animation_step_time: int = None):
395
+ if animation_steps is None:
396
+ from .designs.animation import get_animation_steps
397
+ animation_steps = get_animation_steps()
398
+ if animation_step_time is None:
399
+ from .designs.animation import get_animation_step_time
400
+ animation_step_time = get_animation_step_time()
409
401
  check = self.attributes.check
410
402
  uncheck = self.attributes.uncheck
411
- if uncheck.pressed.border_color2 is None:
412
- uncheck.pressed.border_color2 = uncheck.pressed.border_color
413
- if check.pressed.border_color2 is None:
414
- check.pressed.border_color2 = check.pressed.border_color
415
- if uncheck.pressed.border_color2_opacity is None:
416
- uncheck.pressed.border_color2_opacity = uncheck.pressed.border_color_opacity
417
- if check.pressed.border_color2_opacity is None:
418
- check.pressed.border_color2_opacity = check.pressed.border_color_opacity
419
- if self.attributes.checked:
420
- self.attributes.checked = False
421
- back_colors = self.generate_hex2hex(
422
- check.pressed.back_color, uncheck.rest.back_color, steps
423
- )
424
- border_colors = self.generate_hex2hex(
425
- check.pressed.border_color, uncheck.rest.border_color, steps
426
- )
427
- border_colors2 = self.generate_hex2hex(
428
- check.pressed.border_color2, uncheck.rest.border_color2, steps
429
- )
430
- text_colors = self.generate_hex2hex(
431
- check.pressed.text_color, uncheck.rest.text_color, steps
432
- )
433
- import numpy as np
434
- back_opacitys = np.linspace(
435
- float(check.pressed.back_opacity), float(uncheck.rest.back_opacity), steps).tolist()
436
- border_color_opacitys = np.linspace(
437
- float(check.pressed.border_color_opacity), float(uncheck.rest.border_color_opacity), steps).tolist()
438
- border_color2_opacitys = np.linspace(
439
- float(check.pressed.border_color2_opacity), float(uncheck.rest.border_color2_opacity), steps).tolist()
440
- else:
441
- self.attributes.checked = True
442
- back_colors = self.generate_hex2hex(
443
- uncheck.pressed.back_color, check.rest.back_color, steps
444
- )
445
- border_colors = self.generate_hex2hex(
446
- uncheck.pressed.back_color, check.rest.back_color, steps
447
- )
448
- border_colors2 = self.generate_hex2hex(
449
- uncheck.pressed.border_color2, check.rest.border_color2, steps
450
- )
451
- text_colors = self.generate_hex2hex(
452
- uncheck.pressed.text_color, check.rest.text_color, steps
453
- )
454
- import numpy as np
455
- back_opacitys = np.linspace(float(uncheck.pressed.back_opacity), float(check.rest.back_opacity),
456
- steps).tolist()
457
- border_color_opacitys = np.linspace(float(uncheck.pressed.border_color_opacity), float(check.rest.border_color_opacity),
458
- steps).tolist()
459
- border_color2_opacitys = np.linspace(float(uncheck.pressed.border_color2_opacity),
460
- float(check.rest.border_color2_opacity),
461
- steps).tolist()
462
- for i in range(steps):
463
- def update(ii=i):
464
- from easydict import EasyDict
465
- tempcolor = EasyDict(
466
- {
467
- "back_color": back_colors[ii],
468
- "back_opacity": back_opacitys[ii],
469
- "border_color": border_colors[ii],
470
- "border_color_opacity": str(border_color_opacitys[ii]),
471
- "border_color2": border_colors2[ii],
472
- "border_color2_opacity": str(border_color2_opacitys[ii]),
473
- "border_width": 1,
474
- "text_color": text_colors[ii],
475
- "radius": 6,
476
- }
403
+ if not animation_steps == 0 or not animation_step_time == 0:
404
+ steps = animation_steps
405
+ if uncheck.pressed.border_color2 is None:
406
+ uncheck.pressed.border_color2 = uncheck.pressed.border_color
407
+ if check.pressed.border_color2 is None:
408
+ check.pressed.border_color2 = check.pressed.border_color
409
+ if uncheck.pressed.border_color2_opacity is None:
410
+ uncheck.pressed.border_color2_opacity = uncheck.pressed.border_color_opacity
411
+ if check.pressed.border_color2_opacity is None:
412
+ check.pressed.border_color2_opacity = check.pressed.border_color_opacity
413
+ if self.attributes.checked:
414
+ self.attributes.checked = False
415
+ back_colors = self.generate_hex2hex(
416
+ check.pressed.back_color, uncheck.rest.back_color, steps
417
+ )
418
+ border_colors = self.generate_hex2hex(
419
+ check.pressed.border_color, uncheck.rest.border_color, steps
477
420
  )
478
- self._draw(None, tempcolor)
479
- self.after(i*10, update)
480
- self.after(steps*10+10, lambda: self._draw(None, None))
421
+ border_colors2 = self.generate_hex2hex(
422
+ check.pressed.border_color2, uncheck.rest.border_color2, steps
423
+ )
424
+ text_colors = self.generate_hex2hex(
425
+ check.pressed.text_color, uncheck.rest.text_color, steps
426
+ )
427
+ import numpy as np
428
+ back_opacitys = np.linspace(
429
+ float(check.pressed.back_opacity), float(uncheck.rest.back_opacity), steps).tolist()
430
+ border_color_opacitys = np.linspace(
431
+ float(check.pressed.border_color_opacity), float(uncheck.rest.border_color_opacity), steps).tolist()
432
+ border_color2_opacitys = np.linspace(
433
+ float(check.pressed.border_color2_opacity), float(uncheck.rest.border_color2_opacity), steps).tolist()
434
+ else:
435
+ self.attributes.checked = True
436
+ back_colors = self.generate_hex2hex(
437
+ uncheck.pressed.back_color, check.rest.back_color, steps
438
+ )
439
+ border_colors = self.generate_hex2hex(
440
+ uncheck.pressed.back_color, check.rest.back_color, steps
441
+ )
442
+ border_colors2 = self.generate_hex2hex(
443
+ uncheck.pressed.border_color2, check.rest.border_color2, steps
444
+ )
445
+ text_colors = self.generate_hex2hex(
446
+ uncheck.pressed.text_color, check.rest.text_color, steps
447
+ )
448
+ import numpy as np
449
+ back_opacitys = np.linspace(float(uncheck.pressed.back_opacity), float(check.rest.back_opacity),
450
+ steps).tolist()
451
+ border_color_opacitys = np.linspace(float(uncheck.pressed.border_color_opacity), float(check.rest.border_color_opacity),
452
+ steps).tolist()
453
+ border_color2_opacitys = np.linspace(float(uncheck.pressed.border_color2_opacity),
454
+ float(check.rest.border_color2_opacity),
455
+ steps).tolist()
456
+ for i in range(steps):
457
+ def update(ii=i):
458
+ from easydict import EasyDict
459
+ tempcolor = EasyDict(
460
+ {
461
+ "back_color": back_colors[ii],
462
+ "back_opacity": back_opacitys[ii],
463
+ "border_color": border_colors[ii],
464
+ "border_color_opacity": str(border_color_opacitys[ii]),
465
+ "border_color2": border_colors2[ii],
466
+ "border_color2_opacity": str(border_color2_opacitys[ii]),
467
+ "border_width": 1,
468
+ "text_color": text_colors[ii],
469
+ "radius": 6,
470
+ }
471
+ )
472
+ self._draw(None, tempcolor)
473
+ self.after(i*animation_step_time, update)
474
+ self.after(steps*animation_step_time+10, lambda: self._draw(None, None))
475
+ else:
476
+ if self.attributes.checked:
477
+ self.attributes.checked = False
478
+ else:
479
+ self.attributes.checked = True
tkflu/tooltip.py CHANGED
@@ -1,5 +1,6 @@
1
1
  from .popupwindow import FluPopupWindow
2
2
  from tkinter import Event, Widget
3
+ import sys
3
4
 
4
5
 
5
6
  class FluToolTip(FluPopupWindow):
@@ -26,7 +27,7 @@ class FluToolTip(FluPopupWindow):
26
27
  self._widget.bind('<Enter>', self.enter, add="+")
27
28
  self._widget.bind('<Leave>', self.leave, add="+")
28
29
 
29
- #self.theme(mode)
30
+ self.theme(mode)
30
31
 
31
32
  def enter(self, event: Event):
32
33
  def check() -> None:
@@ -44,10 +45,12 @@ class FluToolTip(FluPopupWindow):
44
45
 
45
46
  # 渐显动画
46
47
  def fade_in(step=0):
47
- alpha = step / 10 # 分10步从0到1
48
+ FRAMES_COUNT = 20
49
+ alpha = step / FRAMES_COUNT # 按帧数变化,从0到1
48
50
  self.wm_attributes("-alpha", alpha)
49
- if step < 10:
50
- self.after(int(round(self._show_time/10)), lambda: fade_in(step + 1)) # 每50ms增加一次透明度
51
+ if step < FRAMES_COUNT:
52
+ # 每执行一次,增加一次透明度,间隔由帧数决定
53
+ self.after(int(round(self._show_time/FRAMES_COUNT)), lambda: fade_in(step + 1))
51
54
 
52
55
  fade_in() # 启动动画
53
56
 
@@ -103,7 +106,7 @@ class FluToolTip2(FluPopupWindow):
103
106
  self._widget.bind('<Leave>', self.hide, add="+")
104
107
  self._widget.bind('<Motion>', self.move, add="+")
105
108
 
106
- #self.theme(mode)
109
+ self.theme(mode)
107
110
 
108
111
  def show(self, event: Event):
109
112
  self.popup(
@@ -127,7 +130,9 @@ class FluToolTip2(FluPopupWindow):
127
130
  self.configure(
128
131
  background=n["back_color"]
129
132
  )
130
- self.wm_attributes("-transparentcolor", n["back_color"])
133
+
134
+ if sys.platform == "win32": # Only Windows supports the transparentcolor attribute
135
+ self.wm_attributes("-transparentcolor", n["back_color"])
131
136
  #print(n["back_color"])
132
137
  if hasattr(self, "_frame"):
133
138
  self._frame.dconfigure(