亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在關閉python應用程序的事件中附加方法?

如何在關閉python應用程序的事件中附加方法?

函數式編程 2021-05-14 16:12:27
我需要解決以下面臨的問題。我有一個Tkinter UI,其中有3個按鈕(“注冊”,“鎖定文件夾”和“解鎖文件夾”)。與所有應用程序一樣,右上角有一個十字按鈕。請參考以下快照。因此,想法是,當用戶通過此UI解鎖其文件夾,然后按下十字按鈕時,必須關閉該文件夾以及該用戶可能已打開的所有文件夾內容。下面是關閉文件夾的代碼。def lockFolder_crossButton():    if userName.get()!='':      answer_folder = getFolderName()     #####check if the folder has already been locked or not!!!!*********      if os.path.exists('./secretFolder/'+userName.get()):          LockFolder.lockFolders(userName.get(), answer_folder)    global timer_active    timer_active = 'no'    window.destroy()上面的代碼存在于類“ openApplication.py”中,該類在運行該應用程序時啟動。以下Faceface.launch.pyw類的代碼導入此類。#!python2.7import sys, osscriptdir, script = os.path.split(__file__)pkgdir = os.path.join(scriptdir, 'pkgs')sys.path.insert(0, pkgdir)os.environ['PYTHONPATH'] = pkgdir + os.pathsep + os.environ.get('PYTHONPATH', '')# APPDATA should always be set, but in case it isn't, try user home# If none of APPDATA, HOME, USERPROFILE or HOMEPATH are set, this will fail.appdata = os.environ.get('APPDATA', None) or os.path.expanduser('~')if 'pythonw' in sys.executable:    # Running with no console - send all stdstream output to a file.    kw = {'errors': 'replace'} if (sys.version_info[0] >= 3) else {}    sys.stdout = sys.stderr = open(os.path.join(appdata, script+'.log'), 'w', **kw)else:    # In a console. But if the console was started just for this program, it    # will close as soon as we exit, so write the traceback to a file as well.    def excepthook(etype, value, tb):        "Write unhandled exceptions to a file and to stderr."        import traceback        traceback.print_exception(etype, value, tb)        with open(os.path.join(appdata, script+'.log'), 'w') as f:            traceback.print_exception(etype, value, tb, file=f)    sys.excepthook = excepthookif __name__ == '__main__':    from openApplication import self    self那么,有什么想法要解決的嗎?您如何建議解決該問題?
查看完整描述

1 回答

  • 1 回答
  • 0 關注
  • 131 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號