def workaroundForGUI():
""" redirect I/O when in GUI
ref: http://stackoverflow.com/questions/2883205/how-can-i-freeze-a-dual-mode-gui-and-console-application-using-cx-freeze
ref: https://mail.gnome.org/archives/commits-list/2012-November/msg04489.html
ref: http://stackoverflow.com/questions/23505835/cx-freeze-ignores-custom-variables-module
"""
try:
sys.stdout.write("\n")
sys.stdout.flush()
except Exception as e:
class GuiLogger:
logfile = os.path.realpath(os.path.realpath(sys.argv[0]))
logfile = os.path.splitext(logfile)[0] + '.log'
logObj = open(logfile, "w")
def __init__(self):
self.logObj = GuiLogger.logObj
def write(self, data):
self.logObj.write(data)
def flush(self):
self.logObj.flush()
def close(self):
self.flush()
def read(self, data):
pass
sys.stdout = sys.stderr = sys.stdin = sys.__stdout__ = sys.__stdin__ = sys.__stderr__ = GuiLogger()
# ref: http://effbot.org/tkinterbook/tkinter-events-and-bindings.htm
评论列表
文章目录