tkinter root.withdraw 后使用root.wm_deiconify显示,进度条结束后不能自动退出
tkinter
我是在自己程序里几个地方都加了TKinter 进度条或者message box 之类的。
下面先提示“请在Group列中输入NG 或者 OK”。
然后用dispatch 从excel打开一个excel表格,用户输入完保存后, 弹出message box“确认输入完成”,withdraw 之后用root.wm_deiconify()重新显示root,因为还有进度条, 运行结束关掉进度条之后,python 一直显示还在运行没有退出,试了。root.quit(),root.destroy都退不了
python 前面3个黄标提示
“local viable mb/wb/mb1 is assigned but never used ”
root = tkinter.Tk() #https://www.jb51.net/article/183820.htm root.title('Step 1 of 4') # 设置窗口标题
root.geometry('300x140+600+300')
root.withdraw()
EE.message_box('ok','请在Group列中输入NG 或者 OK')
EE.open_csv(os.path.join(configdir02,'fileGroup1.csv'))
root.wm_deiconify()
pb = ttk.Progressbar(root, length =200, maximum = 100)
pb.pack(padx=10,pady=20)#pb.grid(row = 0, column = 1)
def start():
global mergeSingleV,mergeStableV,mergeSingleM,mergeSingleMStep,mergeStableM,mergeOther
#mergeOther = EE.creat_df(mergeOther)
for i in range(0,len(files)):
print(files[i])
tracepath = os.path.join(tracedir,files[i])
data = pd.read_csv(tracepath,index_col= False)
data['Filename'] = files[i]
data = data.merge(configP[['Par','AnalyClass']],on ='Par', how='left')
data = data.merge(configS[['Par','Step','AnalyClass']], on=['Par','Step'],how='left') # AnalyClass_x, AnalyClass_y
data['Class'] = np.where(data['AnalyClass_x'].notnull(), data['AnalyClass_x'], data['AnalyClass_y'])# Bug here AnalyClass_y failed
singleV = data[data['Class']==1].drop(['AnalyClass_x','AnalyClass_y'],axis=1) # only ok4 file?
stableV = data[data['Class']==2].drop(['AnalyClass_x','AnalyClass_y'],axis=1) # dplyr::filter(data, class==2)[,1:5]
singleM = data[data['Class']==3].drop(['AnalyClass_x','AnalyClass_y'],axis=1)
singleMStep = data[data['Class']==4].drop(['AnalyClass_x','AnalyClass_y'],axis=1) #?? 空
stableM = data[data['Class']==5].drop(['AnalyClass_x','AnalyClass_y'],axis=1)
other = data[data['Class'].isnull()].drop(['AnalyClass_x','AnalyClass_y'],axis=1)
mergeSingleV = mergeSingleV.append(singleV) # <- rbind(mergeSingleV,singleV)# cbind() 把矩阵横向合并成一个大矩阵(列方式),而rbind()是纵向合并(行方式)。
mergeSingleV[['Step','Interval']] = mergeSingleV[['Step','Interval']].astype(float)
mergeStableV = mergeStableV.append(stableV) #keep data width and data columns the same for appending
mergeSingleM = mergeSingleM.append(singleM) #Filename
mergeSingleMStep = mergeSingleMStep.append(singleMStep)# Last column:Filename not Class
mergeStableM = mergeStableM.append(stableM)
mergeOther = mergeOther.append(other)
print(files[i])#print(tracepath)
pb['value'] += 100/len(files)
print(pb['value'])
pb.update() # 更新画面
bnt = ttk.Button(root, text = 'start',command= start)#bnt2 = ttk.Button(root, text="Quit", command=quit)
bnt.pack(pady=10) #bnt.grid(row = 0, column = 0)#bnt2.grid(row = 1, column = 1)
root.mainloop() #启动应用程序,启动消息循环
root.destroy()
回答:
messagebox
依赖于window
,如果你没有window
,它就会自动创建一个空窗口。空窗口应该是无法关闭的,除非你先关闭messagebox
的窗口,解决方法一:先创建一个窗口,但用window.withdraw()
隐藏它,再调用messagebox
;方法二:不使用messagebox
,自己用窗口去模拟它的行为,添加几个组件也很简单。Kernel died
一般是环境有点乱,依赖包之间存在冲突之类的,检查下spyder
有没有什么 Log 可以查查。
以上是 tkinter root.withdraw 后使用root.wm_deiconify显示,进度条结束后不能自动退出 的全部内容, 来源链接: utcz.com/p/938205.html