0
我曾经使用Python的交互式编辑器,然后我“升级”到Pyzo(因为IEP被合并到Pyzo中)。我的一个程序使用tkinter来创建一个GUI。用于工作的代码很好:我会将该文件作为脚本运行,然后在解释器中,我将调用main来启动应用程序。如何阻止Pyzo调用mainloop?
代码框架看起来像这样。
def main():
class Application(tk.Frame):
def __init__(self, master=None):
# a bunch of stuff
# several more methods here
front=Application()
front.mainloop()
# then I can either call main in the interpreter, or I can add this:
# the name==main part is to handle some multiprocessing that occurs within the application class
if __name__=="__main__":
main()
这在IEP中很有魅力。然而,在Pyzo中,main()永远不会启动,或者说它启动,但gui从不出现,它不会让我做任何事情。相反,我收到以下消息:注意:GUI事件循环已经在pyzo内核中运行。请注意,进入主循环的功能不会被阻止。
当我使用CPython 3或PyPy解释器时,此消息发生在Pyzo中,但当我使用Anaconda 3时(实际上我需要使用PyPy是因为我所做的工作在计算上很昂贵)。
另一种选择是不使用Pyzo,但这并不好玩。