2016-11-23 142 views
1

我使用Tkinter,Python創建了一個可用的GUI界面。加載GUI需要一兩分鐘,我的問題如下:Python GUI加載時顯示圖像

當python在GUI上執行加載時,是否顯示圖像?

真的很感謝幫助。

+0

你可能會產生一個新的TopLevel,它有一個圖像。我不得不想知道爲什麼你的GUI需要這麼長時間才能加載。 – scotty3785

+0

@ scotty3785,它需要大約10秒鐘來顯示GUI,但是,當我使用pyinstaller打包GUI並將其用於另一臺機器「我正在使用Windows」時,它沒有安裝python,它需要一個小型文件左右顯示它,任何想法? – aBiologist

+0

在開始加載真實用戶界面之前,只需顯示另一個更簡單的用戶界面(只有圖像)? –

回答

2

正如評論中所建議的,您可以使用TopLevel來顯示另一個窗口。 您可以使用<NameOfYourTopLevel>.overrideredirect(1)隱藏窗框。

您可能還會考慮在GUI完成加載後使用.after_idle(<callback>)關閉窗口。

這是更完整的例子。我一直無法複製圖形用戶界面的大延遲,所以模擬了這個self.after(5000,self.splash.destroy)。你應該能夠self.after_idle(self.splash.destroy)

try: 
    import tkinter as tk 
except: 
    import Tkinter as tk 


class App(tk.Frame): 
    def __init__(self,master=None,**kw): 
     self.splash = Splash(root) 
     tk.Frame.__init__(self,master=master,**kw) 
     tk.Label(self,text="MainFrame").grid() 
     self.after(5000,self.splash.destroy) 

class Splash(tk.Toplevel): 
    def __init__(self,master=None,**kw): 
     tk.Toplevel.__init__(self,master=master,**kw) 
     tk.Label(self,text="Show Image here").grid() 
     self.overrideredirect(1) 

if __name__ == '__main__': 
    root = tk.Tk() 

    App(root).grid() 
    root.mainloop() 

This question來代替,這將告訴你如何中心窗口在屏幕上。

+0

什麼樣的說法是? – aBiologist

+0

它是一個函數的句柄/名稱。 – scotty3785

+0

我沒有在我的代碼上測試這個,因爲我遠離計算機,但非常感謝幫助,會告訴我它的結果如何。投票給你我的朋友! – aBiologist