我曾经使用Python的Interactive,然后我“升级”到Pyzo (因为IEP被合并到Pyzo)。我的一个程序使用tkinter创建GUI。过去的代码工作得很好:我会将文件作为脚本运行,然后在解释器中调用main,这将启动应用程序。
代码骨架如下所示。
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,但这并不有趣。
发布于 2017-04-29 14:57:51
我一段时间前就发现了答案,但直到现在我才回过头来发布答案。本质上,Pyzo本身有一个试图检测GUI的设置。将该设置从“自动”切换到“无”设置解决了问题。
https://stackoverflow.com/questions/38650087
复制相似问题