更新button和window
This commit is contained in:
parent
913c4a3496
commit
c60307aa4c
|
@ -108,16 +108,16 @@ class Button:
|
|||
def __init__(self, master=None, root_anim=None, w=80, h=30, text="Button", func=lambda s: print("Press"), color_list: None | dict = None):
|
||||
set_font()
|
||||
self.__func = func
|
||||
self.w = max(80, w)
|
||||
self.w = max(30, w)
|
||||
self.h = max(30, h)
|
||||
self.text = text
|
||||
self.__master = master
|
||||
if (color_list is not None):
|
||||
self.color = color_list
|
||||
if (root_anim == None):
|
||||
self.__root = master
|
||||
self.root = master.root
|
||||
else:
|
||||
self.__root = root_anim
|
||||
self.root = root_anim
|
||||
|
||||
self.canvas = tkinter.Canvas(
|
||||
master, bg=self.color["background"], width=self.w, height=self.h, borderwidth=0, bd=0, highlightcolor=self.color["background"], highlightthickness=0)
|
||||
|
@ -198,12 +198,12 @@ class Button:
|
|||
def bind_anim(self):
|
||||
def anim_magictk():
|
||||
if (self.__is_hover == 1 and self.__flash_t < self.max_flash):
|
||||
self.__flash_t += (1 if (len(self.__root.anim) > 6) else 1)
|
||||
self.__flash_t += (1 if (len(self.root.anim) > 6) else 1)
|
||||
self.__flash_t = min(self.__flash_t, self.max_flash)
|
||||
self.hover_mode = self.__flash_t/self.max_flash
|
||||
self.__update_color()
|
||||
elif (self.__is_hover == 0 and self.__flash_t > 0):
|
||||
self.__flash_t -= (1 if (len(self.__root.anim) > 6) else 1)
|
||||
self.__flash_t -= (1 if (len(self.root.anim) > 6) else 1)
|
||||
self.__flash_t = max(self.__flash_t, 0)
|
||||
self.hover_mode = self.__flash_t/self.max_flash
|
||||
self.__update_color()
|
||||
|
@ -220,16 +220,16 @@ class Button:
|
|||
self.__flash_t -= 1
|
||||
self.hover_mode = self.__flash_t/self.max_flash
|
||||
self.__update_color()
|
||||
self.__root.after(anim_normal, 16)
|
||||
self.root.after(anim_normal, 16)
|
||||
|
||||
try:
|
||||
self.__root.anim == 0
|
||||
self.root.anim == 0
|
||||
except:
|
||||
self.__root.after(anim_normal, 16)
|
||||
self.root.after(anim_normal, 16)
|
||||
else:
|
||||
if (anim_magictk not in self.__root.anim):
|
||||
self.__root.anim.append(anim_magictk)
|
||||
self.__anim_obj_id = self.__root.anim[-1]
|
||||
if (anim_magictk not in self.root.anim):
|
||||
self.root.anim.append(anim_magictk)
|
||||
self.__anim_obj_id = self.root.anim[-1]
|
||||
|
||||
def __bind_event(self):
|
||||
def enter_v(*args):
|
||||
|
@ -347,16 +347,16 @@ class ButtonFill(Button):
|
|||
self.__color_fg = color_type
|
||||
self.__color_fg1 = color_type+"_light3"
|
||||
self.__color_fg2 = color_type+"_dark"
|
||||
self.w = max(80, w)
|
||||
self.w = max(30, w)
|
||||
self.h = max(30, h)
|
||||
self.text = text
|
||||
self.__master = master
|
||||
if (color_list is not None):
|
||||
self.color = color_list
|
||||
if (root_anim == None):
|
||||
self.__root = master
|
||||
self.root = master.root
|
||||
else:
|
||||
self.__root = root_anim
|
||||
self.root = root_anim
|
||||
|
||||
self.canvas = tkinter.Canvas(
|
||||
master, bg=self.color["background"], width=self.w, height=self.h, borderwidth=0, bd=0, highlightcolor=self.color["background"], highlightthickness=0)
|
||||
|
@ -428,12 +428,12 @@ class ButtonFill(Button):
|
|||
def bind_anim(self):
|
||||
def anim_magictk():
|
||||
if (self.__is_hover == 1 and self.__flash_t < self.max_flash):
|
||||
self.__flash_t += (1 if (len(self.__root.anim) > 6) else 1)
|
||||
self.__flash_t += (1 if (len(self.root.anim) > 6) else 1)
|
||||
self.__flash_t = min(self.__flash_t, self.max_flash)
|
||||
self.hover_mode = self.__flash_t/self.max_flash
|
||||
self.__update_color()
|
||||
elif (self.__is_hover == 0 and self.__flash_t > 0):
|
||||
self.__flash_t -= (1 if (len(self.__root.anim) > 6) else 1)
|
||||
self.__flash_t -= (1 if (len(self.root.anim) > 6) else 1)
|
||||
self.__flash_t = max(self.__flash_t, 0)
|
||||
self.hover_mode = self.__flash_t/self.max_flash
|
||||
self.__update_color()
|
||||
|
@ -450,16 +450,16 @@ class ButtonFill(Button):
|
|||
self.__flash_t -= 1
|
||||
self.hover_mode = self.__flash_t/self.max_flash
|
||||
self.__update_color()
|
||||
self.__root.after(anim_normal, 16)
|
||||
self.root.after(anim_normal, 16)
|
||||
|
||||
try:
|
||||
self.__root.anim == 0
|
||||
self.root.anim == 0
|
||||
except:
|
||||
self.__root.after(anim_normal, 16)
|
||||
self.root.after(anim_normal, 16)
|
||||
else:
|
||||
if (anim_magictk not in self.__root.anim):
|
||||
self.__root.anim.append(anim_magictk)
|
||||
self.__anim_obj_id = self.__root.anim[-1]
|
||||
if (anim_magictk not in self.root.anim):
|
||||
self.root.anim.append(anim_magictk)
|
||||
self.__anim_obj_id = self.root.anim[-1]
|
||||
|
||||
def __bind_event(self):
|
||||
def enter_v(*args):
|
||||
|
|
|
@ -22,6 +22,7 @@ try:
|
|||
import photoload
|
||||
except ImportError:
|
||||
from magictk import photoload
|
||||
import sys
|
||||
|
||||
WIN_INF = -10000
|
||||
|
||||
|
@ -152,6 +153,7 @@ class Window(ttk.Frame):
|
|||
titles.bind("<ButtonRelease-1>", special_move)
|
||||
|
||||
def __init__(self, w=500, h=350, title="MagicTk", color_list: None | dict = None) -> None:
|
||||
self.root = self
|
||||
self.title = title
|
||||
self.w = w
|
||||
self.h = h
|
||||
|
@ -196,9 +198,13 @@ class Window(ttk.Frame):
|
|||
delta_t = time.time()-t_start
|
||||
if (delta_t > 0.02): # flash animation
|
||||
t_start = time.time()
|
||||
n = 0
|
||||
for i in self.anim:
|
||||
if (i is not None):
|
||||
i()
|
||||
retn = i()
|
||||
if (retn == -1):
|
||||
self.anim[n] = None
|
||||
n += 1
|
||||
self.anim = [i for i in self.anim if i is not None]
|
||||
else:
|
||||
pass
|
||||
|
|
Loading…
Reference in New Issue