2016-07-29 54 views
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,但這並不好玩。

回答

0

前段時間我發現了答案,但直到現在我纔回復發表答案。從本質上講,Pyzo本身就有一個試圖檢測GUI的設置。將該設置從「自動」切換到「無」可解決問題。