2017-06-02 65 views
-4

我想在按下窗口的退出按鈕時安全關閉文件文本。Matplotlib:關閉圖形時關閉文件文本

此外,是否有可能desable窗口的最小化按鈕?

備註:不使用QT!

+0

的一部分可能的解決方案有一個看看:https://matplotlib.org/examples/event_handling/close_event.html。但請展示一些主動權,並告訴我們您嘗試了什麼,哪些方法無效,您卡在哪裏,...... – Bart

+0

關於禁用最小化按鈕:您昨天已經在這裏問過這個問題了...... 。 – Bart

回答

-1

的問題

class ControlSys(): 
    def __init__(self, fig): 
     self.fig = fig 
     self.fig.canvas.mpl_connect('close_event', self.handle_close) 

    def handle_close(self, event): 
     event.canvas.figure.has_been_closed = True 
     fileResults.close() 

    # code..... 

if __name__ == '__main__':  
    fileResults = open("path", "a")  
    fig = plt.subplots(1, 1) 
    # write into the file..." 
    # code... 

    plt.show() 
+0

解決方案?它不起作用.... – Bart

+0

它是我的代碼的一部分,它的工作對我來說 – naddoth

+0

*「它爲我工作」*;那很棒!不幸的是,它不適用於其他人,因爲此代碼根本無法工作。如果您創建了一個*最小,完整且可驗證的示例*(https://stackoverflow.com/help/mcve),那麼您可以幫助某人解答此問題,即可以實際按廣告形式運行的簡單可複製代碼。 – Bart