[Python] 纯文本查看 复制代码import win32com.client as wc,win32gui as wg,threading as xc,time,tkinter as tk,win32api as wa,win32con as wn,multiprocessing as jc
def init_window():
global cs,wd
wd = tk.Tk()
cs = tk.Canvas(wd,
width = 800,
height = 500,
bg = 'white')
wd.minsize(800, 500) # 最小尺寸
wd.maxsize(800, 500)
wd.title('DDTHelper')
pic = tk.PhotoImage(file="pic.png")
cs.create_image(400,250,image = pic)
cs.pack()
bt = tk.Button(wd,
text='初始化',
bg=('white'),
font=('微软雅黑',20),
width=155,
height=48,
command=BT_onCreat)
bt.pack()
cs.create_window(530,70,
width=155,
height=48,
window=bt)
wd.mainloop()
def init_control(Znum,name):
global v1,v2,v3,tx1,t2,tx2,t3,tx3,txn1,txn2,txn3
if Znum==1:
v1=tk.IntVar()
tx1=tk.StringVar()
#txn1=tk.StringVar()
elif Znum==2:
v2=tk.IntVar()
tx2=tk.StringVar()
#txn2=tk.StringVar()
elif Znum==3:
v3=tk.IntVar()
tx3=tk.StringVar()
#txn3=tk.StringVar()
exec('tx{}.set("未运行")'.format(Znum))
exec('lb{} = tk.Label(wd,text="{}",bg=("#ffffff"),font=("微软雅黑",20))'.format(Znum,name))
#exec('lbn{} = tk.Label(wd,textvariable=txn{},bg=("#ffffff"),font=("微软雅黑",10))'.format(Znum,Znum))
exec('cb{} = tk.Checkbutton(wd,textvariable=tx{},bg=("#ffffff"),font=("微软雅黑",10),variable = v{}, height=5,width = 0,command=BT_onRun{})'.format(Znum,Znum,Znum,Znum))
exec('cb{}.pack()'.format(Znum))
exec('lb{}.pack()'.format(Znum))
#exec('lbn{}.pack()'.format(Znum))
Ytmp=Znum*100
Ytmp=Ytmp+70
exec('cs.create_window(630,{},width=0,height=0,window=lb{})'.format(Ytmp,Znum))
Ytmp=Ytmp+40
#exec('cs.create_window(630,{},width=35,height=25,window=lbn{})'.format(Ytmp,Znum))
exec('cs.create_window(710,{},width=70,height=25,window=cb{})'.format(Ytmp,Znum))
def BT_onCreat():
global Znum,D1,D2,D3,conT
Znum = 0
wg.EnumWindows(get_all_hwnd, 0)
conT=jc.Manager().Array("i",[3,0,0,0])#用来控制进程
#lock = jc.Lock()#用来给进程运行顺序排序,防止显示错乱,打包成exe时可以去除(如果出现错误 windos 什么的就改成lock = jc.Manager.Lock() 这样就可以了,或者删掉Manager)
#lock不稳定,弃用
for h,t in hwnd_title.items():
if "4399" in t:
hwnd = t.split("|")[3]
name = t.split("|")[2]
print("账号:" + name + "句柄:" + hwnd)
Znum = Znum + 1
hwnd = int(hwnd)
init_control(Znum,name)
if Znum==1:
D1 = jc.Manager().Array("i",[1,hwnd])
elif Znum==2:
D2 = jc.Manager().Array("i",[2,hwnd])
elif Znum==3:
D3 = jc.Manager().Array("i",[3,hwnd])
def get_all_hwnd(hwnd,mouse):
if wg.IsWindow(hwnd) and wg.IsWindowEnabled(hwnd) and wg.IsWindowVisible(hwnd):
hwnd_title.update({hwnd:wg.GetWindowText(hwnd)})
def Con(data,conT):
#l.acquire()#锁
#try:
print("运行成功")
#finally:
#l.release()
def onRunMan(Znum):
if onRunMan2(Znum) == 1:
conT[Znum]=0
exec('p{} = jc.Process(target=Con,args=(D{},conT))'.format(Znum,Znum))
exec('p{}.daemon=True'.format(Znum))
exec('tx{}.set("运行中")'.format(Znum))
exec('p{}.start()'.format(Znum))
else:
conT[Znum]=1
exec('tx{}.set("未运行")'.format(Znum))
def onRunMan2(Znum):
if Znum ==1:
return v1.get()
elif Znum == 2:
return v2.get()
elif Znum ==3:
return v3.get()
def BT_onRun1():
onRunMan(1)
def BT_onRun2():
onRunMan(2)
def BT_onRun3():
onRunMan(3)
if __name__ == '__main__':
hwnd_title = dict()
init_window()