继承tkk.frame,可放置控件,更改分割颜色

This commit is contained in:
cxy_kevin 2024-03-17 17:46:57 +08:00 committed by cxykevin
parent 2b6d3b1d19
commit 909d242830
2 changed files with 10 additions and 4 deletions

2
.vscode/launch.json vendored
View File

@ -5,7 +5,7 @@
"version": "0.2.0",
"configurations": [
{
"name": "Python 调试程序: 当前文件",
"name": "Python 调试",
"type": "debugpy",
"request": "launch",
"program": "debug.py",

View File

@ -26,7 +26,7 @@ except ImportError:
WIN_INF = 10000
class Window():
class Window(ttk.Frame):
x = 200
y = 200
w = 500
@ -45,6 +45,7 @@ class Window():
def update_size(self) -> None:
self.tk_w_without_bar.set(self.w-48*3)
self.place(x=8, y=self.top_h+1+8, width=self.w-16, height=self.h-1-16)
self.main_tk.geometry(
f"{self.w}x{self.h+self.top_h}+{self.x}+{self.y}")
self.__fake_tk.geometry(
@ -63,7 +64,7 @@ class Window():
self.style.configure(
'Root.TFrame', background=self.color["background"])
self.style.configure(
'Splitline.TFrame', background=color_tmpl.setlight(self.color["border_base"], 0.8))
'Splitline.TFrame', background=self.color["border_light"])
self.style.configure(
'BarExitButton.TFrame', background=self.color["background"])
self.style.configure(
@ -136,8 +137,8 @@ class Window():
control_frame.pack(anchor="e", side='right')
title_frame.bind("<Button-1>", start_move)
title_frame.bind("<B1-Motion>", move_win)
title_frame.bind("<ButtonRelease-1>", special_move)
_window_ctl.exit_btn_set(self, root)
_window_ctl.zoom_btn_set(self, root)
_window_ctl.iconic_btn_set(self, root)
@ -148,6 +149,7 @@ class Window():
titles.pack()
titles.bind("<Button-1>", start_move)
titles.bind("<B1-Motion>", move_win)
titles.bind("<ButtonRelease-1>", special_move)
def __init__(self, w=500, h=350, title="MagicTk", color_list: None | dict = None) -> None:
self.title = title
@ -163,6 +165,10 @@ class Window():
self.tk_w_without_bar = tkinter.IntVar()
self.tk_w_without_bar.set(self.w-48*3)
ttk.Widget.__init__(self, self.main_tk, "ttk::frame", {
"style": "Main.TFrame"})
self.place(x=8, y=self.top_h+1+8, width=self.w-16, height=self.h-1-16)
self.update_size()
self.__fake_tk.title(self.title)
self.main_tk.title(self.title)