2017-04-11 50 views
0

我的问题是,我有一个在tkinter中绘制的图形绘制一些地图和信息,该部分工程很好,但是当我尝试用X按钮关闭程序窗口中,进程仍在运行,我必须用stop按钮来终止进程,因为他们推荐在CMD中运行,我在windows上执行了它,并检查任务管理器,并在关闭程序后继续进行,我能做些什么来解决这个问题? 这里是剧本的结构:也许这个问题已经随着剧情做按tkinter上的退出按钮后无法完成处理

#This is some figure where i plot the maps 
#marco de imagen principal 
f = plt.figure(figsize=(3,3)) 
axe = f.add_subplot(111) 
#axe = f.add_subplot(111) 
#plt.axis('off') 
axe.format_coord = lambda x, y: '' 

#marco de ploteo de mapa 
figu=plt.Figure(figsize=(2,2)) 
#ploteo=figu.add_subplot(111) 
ploteo=figu.add_axes([0, 0, 1, 1]) 
ploteo.format_coord = lambda x, y: '' 
plt.axis('off') 


Class Inicio(tk.Tk): 
    def __init__(self, *args, **kwargs): 
    #I initialize all the menu, labels, variables and canvas and some other functions 

    def libro(self): 

    def onpress(self,event): 
    . 
    . 
    . 
    and more funtions 


ex = Inicio() 
ex.geometry("1280x720") 

ex.mainloop() 

+0

我无法在Windows 7,Python 2.7上重现该问题。也许这个问题是由于你的'Inicio'班的某些事情造成的。或者它可能是一个硬件特定的错误? (http://stackoverflow.com/questions/39601107/python-tkinter-window-not-closing) – Josselin

+0

mmm我不认为是一个具体的错误,我已经尝试在Ubuntu和Windows上,问题仍然存在。感谢无论如何:) – Ivan

回答

0

你有没有试过包括一个协议来处理关闭X按钮?

import tkMessageBox as tmb 

def __init__(self, *args, **kwargs): 
    # All your stuff 
    self.protocol('WM_DELETE_WINDOW', self.close_app) 

def close_app(self): 
    if tmb.askokcancel("Close", "Are you sure...?"): 
     self.destroy() 

这假定self.destroy()通过ex.mainloop(),因为它是你的最通话应用到您的root使用TKinter框架。由ex.mainloop()创建的框架上的self.destroy()也将结束mainloop()以及root

+0

谢谢,我遵循你的指示,但仍然继续在背景上,但后来我改变'self.destroy()''退出()',并完美地工作! – Ivan