初步完成scrollframe,缺失自动配置大小等
Build and Publish / Run (push) Successful in 44s
Details
Build and Publish / Run (push) Successful in 44s
Details
This commit is contained in:
parent
983dff8921
commit
1de2bda297
16
debug.py
16
debug.py
|
@ -85,8 +85,20 @@ if __name__ == "__main__":
|
||||||
magictk.Entry(frame7, w=200).pack(side='left')
|
magictk.Entry(frame7, w=200).pack(side='left')
|
||||||
frame7.pack()
|
frame7.pack()
|
||||||
|
|
||||||
frame8 = magictk.Frame(win)
|
frame8 = magictk.Container(win, h=10, container_h=30*6*5)
|
||||||
magictk.ScrollBar(frame8, h=200, allh=100).pack(side='left')
|
for i in range(5):
|
||||||
|
magictk.Button(frame8, text="Default",
|
||||||
|
func=lambda s: print("Btn 1")).pack()
|
||||||
|
magictk.ButtonFill(frame8, text="Primary",
|
||||||
|
func=lambda s: print("Btn 2")).pack()
|
||||||
|
magictk.ButtonFill(frame8, color_type="success", text="Success",
|
||||||
|
func=lambda s: print("Btn 3")).pack()
|
||||||
|
magictk.ButtonFill(frame8, color_type="info", text="Info",
|
||||||
|
func=lambda s: print("Btn 4")).pack()
|
||||||
|
magictk.ButtonFill(frame8, color_type="warning", text="Warning",
|
||||||
|
func=lambda s: print("Btn 5")).pack()
|
||||||
|
magictk.ButtonFill(frame8, color_type="danger", text="Danger",
|
||||||
|
func=lambda s: print("Btn 6")).pack()
|
||||||
frame8.pack()
|
frame8.pack()
|
||||||
|
|
||||||
win.mainloop()
|
win.mainloop()
|
||||||
|
|
|
@ -5,6 +5,6 @@ from magictk.progressbar import ProgressBar
|
||||||
from magictk.checkbox import Checkbox, RadioGroup
|
from magictk.checkbox import Checkbox, RadioGroup
|
||||||
from magictk.submenu import Menu, MenuObjs
|
from magictk.submenu import Menu, MenuObjs
|
||||||
from magictk.select import Select
|
from magictk.select import Select
|
||||||
from magictk.frame import Frame
|
from magictk.frame import Frame, Container
|
||||||
from magictk.entry import Entry
|
from magictk.entry import Entry
|
||||||
from magictk.scrollbar import ScrollBar
|
from magictk.scrollbar import ScrollBar
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import tkinter
|
import tkinter
|
||||||
from tkinter import ttk
|
from tkinter import ttk
|
||||||
from magictk import color_tmpl
|
from magictk import color_tmpl
|
||||||
|
from magictk.scrollbar import ScrollBar
|
||||||
|
|
||||||
|
|
||||||
class Frame(tkinter.Frame):
|
class Frame(tkinter.Frame):
|
||||||
|
@ -8,6 +9,35 @@ class Frame(tkinter.Frame):
|
||||||
|
|
||||||
def __init__(self, master, color=None, *args, **kwargs):
|
def __init__(self, master, color=None, *args, **kwargs):
|
||||||
self.root = master.root
|
self.root = master.root
|
||||||
kwargs["bg"] = self.color["background"]
|
if ("bg" not in kwargs and "background" not in kwargs):
|
||||||
|
kwargs["bg"] = self.color["background"]
|
||||||
super().__init__(master, *args, **kwargs)
|
super().__init__(master, *args, **kwargs)
|
||||||
self.configure()
|
self.configure()
|
||||||
|
|
||||||
|
|
||||||
|
class Container(Frame):
|
||||||
|
color = color_tmpl.default_color
|
||||||
|
|
||||||
|
def scroll_callback(self, obj, pos):
|
||||||
|
super().place(x=0, y=-pos, w=self.w-7, h=self.container_h)
|
||||||
|
|
||||||
|
def __init__(self, master, color=None, w=300, h=200, container_h=500, *args, **kwargs):
|
||||||
|
self.root = master.root
|
||||||
|
self.w = w
|
||||||
|
self.h = h
|
||||||
|
self.container_h = container_h
|
||||||
|
self.root_frame = Frame(master, width=w, height=h)
|
||||||
|
super().__init__(self.root_frame, *args, **kwargs)
|
||||||
|
super().place(x=0, y=0, w=self.w-7, h=container_h)
|
||||||
|
self.scroll = ScrollBar(self.root_frame,
|
||||||
|
h=self.h, allh=self.container_h-self.h, maxh=self.h, callback=self.scroll_callback)
|
||||||
|
self.scroll.place(x=self.w-7, y=0, w=8, relheight=1)
|
||||||
|
|
||||||
|
def pack(self, *args, **kwargs):
|
||||||
|
self.root_frame.pack(*args, **kwargs)
|
||||||
|
|
||||||
|
def grid(self, *args, **kwargs):
|
||||||
|
self.root_frame.grid(*args, **kwargs)
|
||||||
|
|
||||||
|
def place(self, *args, **kwargs):
|
||||||
|
self.root_frame.place(*args, **kwargs)
|
||||||
|
|
|
@ -59,9 +59,10 @@ class ScrollBar:
|
||||||
y_n += 1
|
y_n += 1
|
||||||
|
|
||||||
def __init__(self, master=None, root_anim=None, w=None, h=8, colors="primary", color_list: dict = None, allh=100,
|
def __init__(self, master=None, root_anim=None, w=None, h=8, colors="primary", color_list: dict = None, allh=100,
|
||||||
maxh=50):
|
maxh=50, callback=lambda obj, val: None):
|
||||||
self._r_allh = allh
|
self._r_allh = allh
|
||||||
self._r_maxh = maxh
|
self._r_maxh = maxh
|
||||||
|
self.callback = callback
|
||||||
self.w = 8
|
self.w = 8
|
||||||
self.h = h
|
self.h = h
|
||||||
self.__master = master
|
self.__master = master
|
||||||
|
@ -125,7 +126,7 @@ class ScrollBar:
|
||||||
delta_y = event.y-self.scroll_y
|
delta_y = event.y-self.scroll_y
|
||||||
self.scroll_y = min(self.h-self.bar_len,
|
self.scroll_y = min(self.h-self.bar_len,
|
||||||
max(0, self.scroll_y+delta_y-self.move_start))
|
max(0, self.scroll_y+delta_y-self.move_start))
|
||||||
print(self.get())
|
self.callback(self, self.get())
|
||||||
self.update_pos()
|
self.update_pos()
|
||||||
|
|
||||||
def mouse_release(event: tkinter.Event):
|
def mouse_release(event: tkinter.Event):
|
||||||
|
@ -152,54 +153,6 @@ class ScrollBar:
|
||||||
self.__draw_corner(0, 1, 0, self.scroll_y+self.bar_len-4+1,
|
self.__draw_corner(0, 1, 0, self.scroll_y+self.bar_len-4+1,
|
||||||
self.color["border_light"], "bottomside", bgcolor=self.color["background"])
|
self.color["border_light"], "bottomside", bgcolor=self.color["background"])
|
||||||
|
|
||||||
def __update_pixel(self):
|
|
||||||
self.__move_progress_pixel = max(4, int((self.w-6)*self.progress))
|
|
||||||
|
|
||||||
def add_progress(self, n):
|
|
||||||
self.progress = max(min(self.progress+n, 1.0), 0.0)
|
|
||||||
self.__update_pixel()
|
|
||||||
|
|
||||||
def set_progress(self, n):
|
|
||||||
self.progress = max(min(n, 1.0), 0.0)
|
|
||||||
self.__update_pixel()
|
|
||||||
|
|
||||||
def bind_anim(self):
|
|
||||||
def anim_magictk():
|
|
||||||
if (int(self.__progress_pixel) < int(self.__move_progress_pixel)):
|
|
||||||
if (self.__move_progress_pixel-self.__progress_pixel > 8):
|
|
||||||
self.__progress_pixel += 8
|
|
||||||
else:
|
|
||||||
add_n = int(
|
|
||||||
(self.__progress_pixel-self.__move_progress_pixel)/2)
|
|
||||||
if (add_n <= 2):
|
|
||||||
self.__progress_pixel = self.__move_progress_pixel
|
|
||||||
else:
|
|
||||||
self.__progress_pixel += add_n
|
|
||||||
self.__update_prog()
|
|
||||||
elif (int(self.__progress_pixel) > int(self.__move_progress_pixel)):
|
|
||||||
if (self.__progress_pixel-self.__move_progress_pixel > 8):
|
|
||||||
self.__progress_pixel -= 8
|
|
||||||
else:
|
|
||||||
add_n = int(
|
|
||||||
(self.__progress_pixel-self.__move_progress_pixel)/2)
|
|
||||||
if (add_n <= 2):
|
|
||||||
self.__progress_pixel = self.__move_progress_pixel
|
|
||||||
else:
|
|
||||||
self.__progress_pixel -= add_n
|
|
||||||
self.__update_prog()
|
|
||||||
|
|
||||||
def anim_normal(*args):
|
|
||||||
self.__root.after(anim_normal, 16)
|
|
||||||
|
|
||||||
try:
|
|
||||||
self.__root.anim == 0
|
|
||||||
except:
|
|
||||||
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]
|
|
||||||
|
|
||||||
def get(self):
|
def get(self):
|
||||||
if (self.scroll_y+self.bar_len >= self.h):
|
if (self.scroll_y+self.bar_len >= self.h):
|
||||||
return self._r_allh
|
return self._r_allh
|
||||||
|
|
Loading…
Reference in New Issue