Skip to content

Commit de30fcc

Browse files
committed
菜单功能
1 parent 34d3f8b commit de30fcc

13 files changed

+449
-134
lines changed

preview/generate_win.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import json
22
from operator import methodcaller
3+
from tkinter import Menu
34

45
from pytpl.base_tpl import BaseTpl
56
from pytpl.frame_tpl import FrameTpl
@@ -21,8 +22,8 @@ def build(self):
2122
win = self.tk_json['win']
2223
root = WinTpl().make(win)
2324
root.attributes("-topmost", True)
24-
2525
self.create_elements(win['elements'], root)
26+
root.config(menu=self.create_menu(win['menus'], root))
2627
root.mainloop()
2728

2829
def create_elements(self, elements, root):
@@ -43,6 +44,26 @@ def create_elements(self, elements, root):
4344
caller = methodcaller(ele['type'], ele)
4445
caller(base_tpl)
4546

47+
def create_menu(self, menus, root):
48+
menu_obj = Menu(root, tearoff=False)
49+
for menu in menus:
50+
if 'children' in menu.keys():
51+
submenu = self.create_submenu(menu['children'], menu_obj)
52+
menu_obj.add_cascade(label=menu['name'], menu=submenu)
53+
else:
54+
menu_obj.add_command(label=menu['name'])
55+
return menu_obj
56+
57+
def create_submenu(self, menus, parent):
58+
menu_obj = Menu(parent, tearoff=False)
59+
for menu in menus:
60+
if 'children' in menu.keys():
61+
submenu = self.create_submenu(menu['children'], menu_obj)
62+
menu_obj.add_cascade(label=menu['name'], menu=submenu)
63+
else:
64+
menu_obj.add_command(label=menu['name'])
65+
return menu_obj
66+
4667

4768
if __name__ == "__main__":
4869
with open(file="tk.json", encoding="utf8") as f:

preview/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# 版本号
1313
from generate_win import GenerateWin
1414

15-
version = "2.1.2"
15+
version = "2.2.0"
1616
# 预览服务默认地址
1717
host = ("127.0.0.1", 12300)
1818

preview/requirements.txt

206 Bytes
Binary file not shown.

preview/tk.json

Lines changed: 140 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -1,144 +1,165 @@
11
{
22
"win": {
3-
"top": 124,
4-
"left": 454,
5-
"width": 600,
6-
"height": 500,
7-
"text": "组件演示DEMO ~ Tkinter布局助手",
3+
"top": 97,
4+
"left": 191,
5+
"width": 576,
6+
"height": 207,
7+
"id": "lbhj5xtk",
8+
"type": "tk_win",
9+
"text": "主机端口检测",
10+
"frame": true,
811
"elements": [
912
{
10-
"top": 390,
11-
"left": 40,
12-
"width": 450,
13-
"height": 70,
14-
"id": "l5w6b5uv",
15-
"type": "tk_table"
13+
"top": 20,
14+
"left": 10,
15+
"width": "70",
16+
"event_bind_list": [],
17+
"is_show": true,
18+
"height": "25",
19+
"text": "ip/域名",
20+
"id": "l5asydoy",
21+
"type": "tk_label"
1622
},
1723
{
1824
"top": 20,
25+
"left": 90,
26+
"width": 150,
27+
"event_bind_list": [],
28+
"is_show": true,
29+
"height": 24,
30+
"id": "ip",
31+
"type": "tk_input"
32+
},
33+
{
34+
"top": 70,
1935
"left": 10,
20-
"width": 200,
21-
"height": 150,
22-
"frame": true,
23-
"elements": [
24-
{
25-
"top": 20,
26-
"left": 20,
27-
"width": 50,
28-
"height": 24,
29-
"text": "标签",
30-
"id": "l5w6bcqu",
31-
"type": "tk_label"
32-
},
33-
{
34-
"top": 60,
35-
"left": 20,
36-
"width": 50,
37-
"height": 24,
38-
"text": "标签",
39-
"id": "l5w6bfit",
40-
"type": "tk_label"
41-
},
42-
{
43-
"top": 100,
44-
"left": 20,
45-
"width": 150,
46-
"height": 24,
47-
"id": "l5w6blb1",
48-
"type": "tk_select_box"
49-
},
50-
{
51-
"top": 30,
52-
"left": 100,
53-
"width": 50,
54-
"height": 24,
55-
"text": "按钮",
56-
"id": "l5w6cwf9",
57-
"type": "tk_button"
58-
}
59-
],
60-
"id": "l5w6b966",
61-
"type": "tk_frame"
36+
"width": 70,
37+
"event_bind_list": [],
38+
"is_show": true,
39+
"height": "25",
40+
"text": "开始端口",
41+
"id": "l5asyhl5",
42+
"type": "tk_label"
6243
},
6344
{
64-
"top": 30,
65-
"left": 280,
66-
"width": 226,
67-
"height": 152,
68-
"frame": true,
69-
"elements": [
70-
{
71-
"top": 30,
72-
"left": 10,
73-
"width": 50,
74-
"height": 24,
75-
"text": "标签",
76-
"id": "l5w6bw4m",
77-
"type": "tk_label"
78-
},
79-
{
80-
"top": 30,
81-
"left": 70,
82-
"width": 150,
83-
"height": 24,
84-
"id": "l5w6byq2",
85-
"type": "tk_input"
86-
},
87-
{
88-
"top": 80,
89-
"left": 10,
90-
"width": 80,
91-
"height": 24,
92-
"text": "单选框",
93-
"id": "l5w6cmo3",
94-
"type": "tk_radio_button"
95-
},
96-
{
97-
"top": 80,
98-
"left": 120,
99-
"width": 80,
100-
"height": 24,
101-
"text": "多选框",
102-
"id": "l5w6crvh",
103-
"type": "tk_check_button"
104-
}
105-
],
106-
"text": "标签容器",
107-
"id": "l5w6bqvd",
108-
"type": "tk_label_frame"
45+
"top": 70,
46+
"left": 90,
47+
"width": 150,
48+
"event_bind_list": [],
49+
"is_show": true,
50+
"height": 24,
51+
"id": "port_start",
52+
"type": "tk_input"
53+
},
54+
{
55+
"top": 120,
56+
"left": 10,
57+
"width": "70",
58+
"event_bind_list": [],
59+
"is_show": true,
60+
"height": "25",
61+
"text": "结束端口",
62+
"id": "l5asysjt",
63+
"type": "tk_label"
10964
},
11065
{
111-
"top": 190,
112-
"left": 20,
66+
"top": 120,
67+
"left": 90,
11368
"width": 150,
69+
"event_bind_list": [],
70+
"is_show": true,
11471
"height": 24,
115-
"id": "l5w6c93g",
116-
"type": "tk_progressbar"
72+
"id": "port_end",
73+
"type": "tk_input"
11774
},
11875
{
119-
"top": 250,
120-
"left": 20,
121-
"width": 24,
122-
"height": 105,
123-
"id": "l5w6cc5k",
76+
"top": 169,
77+
"left": 89,
78+
"width": 144,
79+
"event_bind_list": [],
80+
"is_show": true,
81+
"height": 24,
82+
"id": "rate",
12483
"type": "tk_progressbar"
12584
},
12685
{
127-
"top": 240,
128-
"left": 410,
129-
"width": 150,
130-
"height": 100,
131-
"id": "l5w6d2zq",
86+
"top": 170,
87+
"left": 10,
88+
"width": 69,
89+
"event_bind_list": [],
90+
"is_show": true,
91+
"height": 24,
92+
"text": "进度",
93+
"id": "l5asz624",
94+
"type": "tk_label"
95+
},
96+
{
97+
"top": 170,
98+
"left": 480,
99+
"width": 86,
100+
"event_bind_list": [],
101+
"is_show": true,
102+
"height": 28,
103+
"text": "开始扫描",
104+
"id": "scan",
105+
"type": "tk_button"
106+
},
107+
{
108+
"top": 170,
109+
"left": 250,
110+
"width": "80",
111+
"event_bind_list": [],
112+
"is_show": true,
113+
"height": 24,
114+
"text": "用时统计",
115+
"id": "l5at0w19",
116+
"type": "tk_label"
117+
},
118+
{
119+
"top": 170,
120+
"left": 340,
121+
"width": 121,
122+
"event_bind_list": [],
123+
"is_show": true,
124+
"height": 24,
125+
"text": "79:30:12",
126+
"id": "time",
127+
"type": "tk_label"
128+
},
129+
{
130+
"top": 20,
131+
"left": 249,
132+
"width": 317,
133+
"event_bind_list": [],
134+
"is_show": true,
135+
"height": 138,
136+
"options": [
137+
"列表框",
138+
"Python",
139+
"Tkinter Helper"
140+
],
141+
"id": "ports",
132142
"type": "tk_list_box"
143+
}
144+
],
145+
"event_bind_list": [],
146+
"menus": [
147+
{
148+
"id": "lbhrd8mf",
149+
"name": "文件",
150+
"call": ""
133151
},
134152
{
135-
"top": 250,
136-
"left": 80,
137-
"width": 286,
138-
"height": 101,
139-
"id": "l5w6d9q6",
140-
"type": "tk_text"
153+
"id": "lbhrftip",
154+
"name": "编辑",
155+
"call": ""
141156
}
142157
]
143-
}
158+
},
159+
"name": "Tkinter布局助手",
160+
"web": "https://pytk.net/tkinter-helper",
161+
"github": "https://github.com/iamxcd/tkinter-helper",
162+
"gitee": "https://gitee.com/iamxcd/tkinter-helper",
163+
"version": "2.4.2",
164+
"qq_group": "788392508"
144165
}

preview/打包说明.md

Lines changed: 0 additions & 9 deletions
This file was deleted.

preview/打包说明.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
3+
## 创建虚拟环境
4+
5+
## 打包命令
6+
pyinstaller -w .\main.py --add-data "static;static" -i .\static\img.png -n "tkinter布局助手预览服务"

0 commit comments

Comments
 (0)