Skip to content

Commit 4b112ff

Browse files
committed
Upload
0 parents  commit 4b112ff

File tree

4 files changed

+136
-0
lines changed

4 files changed

+136
-0
lines changed

control.py

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import winreg
2+
import subprocess
3+
4+
class Controller:
5+
# 导入UI类后,替换以下的 object 类型,将获得 IDE 属性提示功能
6+
ui: object
7+
def __init__(self):
8+
self.app_name = "WeChat.exe"
9+
10+
def get_wechat_path(self):
11+
reg_path = f"SOFTWARE\Tencent\WeChat"
12+
value_name = "InstallPath"
13+
try:
14+
with winreg.OpenKey(winreg.HKEY_CURRENT_USER, reg_path, 0, winreg.KEY_READ) as key:
15+
return winreg.QueryValueEx(key, value_name)[0] + f"\{self.app_name}"
16+
except FileNotFoundError:
17+
return None
18+
19+
20+
def init(self, ui):
21+
"""
22+
得到UI实例,对组件进行初始化配置
23+
"""
24+
self.ui = ui
25+
# TODO 组件初始化 赋值操作
26+
27+
def open_wechat(self, evt):
28+
app_path = self.get_wechat_path()
29+
number = 0
30+
try:
31+
number = (int)(self.ui.tk_text_m27qkagn.get(1.0, "end"))
32+
for i in range(number):
33+
subprocess.Popen(app_path)
34+
except ValueError:
35+
pass
36+

icon.ico

9.44 KB
Binary file not shown.

main.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# 导入布局文件
2+
from ui import Win as MainWin
3+
# 导入窗口控制器
4+
from control import Controller as MainUIController
5+
6+
# 将窗口控制器 传递给UI
7+
app = MainWin(MainUIController())
8+
if __name__ == "__main__":
9+
# 启动
10+
app.resizable(0, 0)
11+
app.mainloop()

ui.py

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import random
2+
from tkinter import *
3+
from tkinter.ttk import *
4+
5+
class WinGUI(Tk):
6+
def __init__(self):
7+
super().__init__()
8+
self.__win()
9+
self.tk_text_m27qkagn = self.__tk_text_m27qkagn(self)
10+
self.tk_button_m27qm1i7 = self.__tk_button_m27qm1i7(self)
11+
self.tk_label_m27qqav2 = self.__tk_label_m27qqav2(self)
12+
13+
def __win(self):
14+
self.title("微信多开助手")
15+
# 设置窗口大小、居中
16+
width = 320
17+
height = 80
18+
screenwidth = self.winfo_screenwidth()
19+
screenheight = self.winfo_screenheight()
20+
geometry = '%dx%d+%d+%d' % (width, height, (screenwidth - width) / 2, (screenheight - height) / 2)
21+
self.geometry(geometry)
22+
23+
self.resizable(width=False, height=False)
24+
25+
def scrollbar_autohide(self,vbar, hbar, widget):
26+
"""自动隐藏滚动条"""
27+
def show():
28+
if vbar: vbar.lift(widget)
29+
if hbar: hbar.lift(widget)
30+
def hide():
31+
if vbar: vbar.lower(widget)
32+
if hbar: hbar.lower(widget)
33+
hide()
34+
widget.bind("<Enter>", lambda e: show())
35+
if vbar: vbar.bind("<Enter>", lambda e: show())
36+
if vbar: vbar.bind("<Leave>", lambda e: hide())
37+
if hbar: hbar.bind("<Enter>", lambda e: show())
38+
if hbar: hbar.bind("<Leave>", lambda e: hide())
39+
widget.bind("<Leave>", lambda e: hide())
40+
41+
def v_scrollbar(self,vbar, widget, x, y, w, h, pw, ph):
42+
widget.configure(yscrollcommand=vbar.set)
43+
vbar.config(command=widget.yview)
44+
vbar.place(relx=(w + x) / pw, rely=y / ph, relheight=h / ph, anchor='ne')
45+
46+
def h_scrollbar(self,hbar, widget, x, y, w, h, pw, ph):
47+
widget.configure(xscrollcommand=hbar.set)
48+
hbar.config(command=widget.xview)
49+
hbar.place(relx=x / pw, rely=(y + h) / ph, relwidth=w / pw, anchor='sw')
50+
51+
def create_bar(self,master, widget,is_vbar,is_hbar, x, y, w, h, pw, ph):
52+
vbar, hbar = None, None
53+
if is_vbar:
54+
vbar = Scrollbar(master)
55+
self.v_scrollbar(vbar, widget, x, y, w, h, pw, ph)
56+
if is_hbar:
57+
hbar = Scrollbar(master, orient="horizontal")
58+
self.h_scrollbar(hbar, widget, x, y, w, h, pw, ph)
59+
self.scrollbar_autohide(vbar, hbar, widget)
60+
61+
def __tk_text_m27qkagn(self,parent):
62+
text = Text(parent)
63+
text.place(x=100, y=16, width=116, height=50)
64+
return text
65+
66+
def __tk_button_m27qm1i7(self,parent):
67+
btn = Button(parent, text="打开", takefocus=False,)
68+
btn.place(x=226, y=16, width=80, height=50)
69+
return btn
70+
71+
def __tk_label_m27qqav2(self,parent):
72+
label = Label(parent,text="数量",anchor="center", )
73+
label.place(x=10, y=16, width=85, height=50)
74+
return label
75+
76+
class Win(WinGUI):
77+
def __init__(self, controller):
78+
self.ctl = controller
79+
super().__init__()
80+
self.__event_bind()
81+
self.__style_config()
82+
self.ctl.init(self)
83+
84+
def __event_bind(self):
85+
self.tk_button_m27qm1i7.bind('<Button>',self.ctl.open_wechat)
86+
pass
87+
88+
def __style_config(self):
89+
pass

0 commit comments

Comments
 (0)