我需要解決以下面臨的問題。我有一個Tkinter UI,其中有3個按鈕(“注冊”,“鎖定文件夾”和“解鎖文件夾”)。與所有應(yīng)用程序一樣,右上角有一個十字按鈕。請參考以下快照。因此,想法是,當用戶通過此UI解鎖其文件夾,然后按下十字按鈕時,必須關(guān)閉該文件夾以及該用戶可能已打開的所有文件夾內(nèi)容。下面是關(guān)閉文件夾的代碼。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”中,該類在運行該應(yīng)用程序時啟動。以下Faceface.launch.pyw類的代碼導(dǎo)入此類。#!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那么,有什么想法要解決的嗎?您如何建議解決該問題?
如何在關(guān)閉python應(yīng)用程序的事件中附加方法?
函數(shù)式編程
2021-05-14 16:12:27