使用TKinter编写界面,实现选择测试用例并执行,最后打印出测试结果。功能是实现了,可是每次一点下开始执行,整个界面就失去响应了,要等到测试用例执行完了,界面才恢复响应,已经把执行用例和画界面分别作为单独的线程来处理了,为什么还是不行?
界面如下:
相关代码如下:
def ExcuteSet():
global Exe_Flag
Exe_Flag=True
#执行测试用例
exe_thread= threading.Thread(target=ExecuteCase)
exe_thread.setDaemon(True)
exe_thread.start()
exe_thread.join()
def Interface():
global ComX,Baud,TBuf
global txt1,txt2,txt3
# 界面
root.title(u'自动化测试工具')
root.geometry('800x600')
#滚动条
scroll1=Tk.Scrollbar(root,orient=Tk.VERTICAL) #滚动条
scroll1.pack(fill="y",side='right')
txt1 = Tk.Text(root,width=60,height=20,border=5,yscrollcommand=scroll1.set)
txt1.pack(side='right',padx=3,pady=1,anchor='c')
txt1.bind("<Key>",TextKey)
scroll1.config(command=txt1.yview)
txt1.place(x=300,y=300)
#scroll1.place(x=750,y=300)
#操作按钮
TBuf = StringVar()
cnv1 = tk.Canvas(root,height=260,width=260)
cnv1.pack(side='bottom',padx=0,pady=0,anchor='c')
cnv1.create_window(60,40,window=ttk.Label(root,text=u'串口号: '))
cnv1.create_window(165,40,window=ttk.Combobox(root,textvariable=ComX,values=['COM1', 'COM2', 'COM3','COM4','COM5', 'COM6', 'COM7','COM8'],width=12))
cnv1.create_window(60,80,window=ttk.Label(root,text=u'波特率: '))
cnv1.create_window(165,80,window=ttk.Combobox(root,textvariable=Baud,values=['4800','9600','14400','19200','38400','57600','115200'],width=12))
cnv1.create_window(70,120,window=ttk.Label(root,text=u'输入目录: '))
cnv1.create_window(240,120,window=ttk.Entry(root,textvariable=TBuf,width=40))
cnv1.create_window(80,150,window=ttk.Button(root,textvariable=OpenOff,command=COMOpen,width=12))
cnv1.create_window(80,180,window=ttk.Button(root,text=u'选择用例',command=SelectCase,width=12))
cnv1.create_window(80,210,window=ttk.Button(root,text=u'开始执行',command=ExcuteSet,width=12))
cnv1.create_window(80,240,window=ttk.Button(root,text=u'停止测试',command=StopTest,width=12))
cnv1.create_window(175,180,window=ttk.Button(root,text=u'清除用例',command=ClearCase,width=12))
cnv1.place(x=320,y=0)
#滚动条
scroll2=Tk.Scrollbar(root,orient=Tk.VERTICAL) #滚动条
scroll2.pack(fill="y",side='left')
#显示测试用例
txt2 = Tk.Text(root,width=40,height=20,border=5,yscrollcommand=scroll2.set)
txt2.pack(padx=3,pady=1,anchor='c')
scroll2.config(command=txt2.yview)
txt2.place(x=0,y=0)
scroll2.place(x=300,y=0)
#显示测试用例执行情况
txt3 = Tk.Text(root,width=40,height=20,border=5)
txt3.pack(padx=3,pady=1,anchor='c')
txt3.place(x=0,y=300)
root.mainloop()
if name=='__main__':
isOpened.clear()
Init() #初始化
Opencom()
threads=[]
#读串口数据
com_thread = threading.Thread(target=COMTrce)
threads.append(com_thread)
#画界面
inter_thread = threading.Thread(target=Interface)
threads.append(inter_thread)
#执行用例
#exe_thread= threading.Thread(target=ExecuteCase)
#threads.append(inter_thread)
for t in threads:
t.setDaemon(True)
t.start()
for t in threads:
t.join()
print "Over!!!!!!!!!!!"