|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 A529231559 于 2019-9-22 01:44 编辑
问题:为什么通过多线程去调用的时候就失败了?我单独在CtrlA文件调用是没有问题的。
代码如下:下面红色部分调用失败
主窗体代码:
from CtrlA import CtrlA
import tkinter
#设置ctrlA自动的输入框1
label3=tkinter.Label(the_window,text="次数",pady=5)
label3.place(x=10,y=250,anchor="nw")
shuru_1=tkinter.StringVar()
shuru1=tkinter.Entry(the_window,bd=4,width=3,justify="left",textvariable=shuru_1,font=("Microsoft YaHei",12))
shuru1.place(x=40,y=250,anchor="nw")
#设置ctrlA自动的输入框2
label4=tkinter.Label(the_window,text="间隔/分",pady=5)
label4.place(x=75,y=250,anchor="nw")
shuru_2=tkinter.StringVar()
shuru2=tkinter.Entry(the_window,bd=4,width=3,justify="left",textvariable=shuru_2,font=("Microsoft YaHei",12))
shuru2.place(x=130,y=250,anchor="nw")
judge_number=0
crucle=0
def gaibian():
global judge_number,crucle
if judge_number == 0:
if shuru_1.get().isdigit() and shuru_2.get().isdigit() :
judge_number=1
ctrlakaishi.config(text="结束")
shuru1.config(state="disabled")
shuru2.config(state="disabled")
def qidong():
global judge_number,crucle
if judge_number==1 and crucle <=int(shuru_1.get()):
def crucle_ctrla():
global crucle
print(listbox1_var1.get()) #打印窗体名称(已封装)
CtrlA(listbox1_var1.get()).ctrla() #listbox1_var1.get()为窗体名称
time.sleep(60*int(shuru_2.get()))
crucle=crucle+1
return qidong()
t=threading.Thread(target=crucle_ctrla)
t.setDaemon(True)
t.start()
threading._VERBOSE = True
return qidong()
else:
print("请输入整数")
elif judge_number==1:
judge_number=0
crucle = 0
ctrlakaishi.config(text="开始")
shuru1.config(state="normal")
shuru2.config(state="normal")
另一CtrlA文件代码:
class CtrlA(object):
def __init__(self,account_mx):
self.mx=account_mx
def ctrla(self):
for i in self.mx:
the_window=win32gui.FindWindow(None,i)
if the_window !=0:
win32gui.SetForegroundWindow(the_window)
time.sleep(1)
KeyEvent('control','down') #按下ctrl键(已封装)
KeyEvent('c','down') #按下c键(已封装)
time.sleep(0.1)
KeyEvent('control','up') #抬起ctrl键(已封装)
KeyEvent('c','up') #抬起c键(已封装)
time.sleep(1)
for j in self.mx:
if j.find("天") != 0 and j.find("空") != 0 and j.find("城") != 0:
force_window1 = win32gui.FindWindow(None,j)
try:
win32gui.SetForegroundWindow(force_window1)
except:
print("未找到")
|
|