2014-10-12 47 views
0

我創建一個閃屏,這將是介紹我的計劃。我已經設法在屏幕上放置一個圖像,但一旦我添加一個按鈕,什麼都沒有出現,甚至沒有出現這個窗口。的Python 2.7.8 Tkinter的GUI,其中包括圖像,按鈕和文本

我試圖做的是對窗口頂部的圖像,其下一個文本框,我的名字「鮑勃約翰」,那麼另一個按鈕,上面寫着"Enter",這將用戶帶到另一節該程序(即啓動應用程序)。所有這些都與中心對齊。

這是我到目前爲止有:

from Tkinter import * 
from PIL import ImageTk, Image 
import os 

#create the window 
root = Tk() 

#modify root window 
root.title("Labeler") 
root.geometry("500x500")#Width x Height 

img = ImageTk.PhotoImage(Image.open("test.gif")) 
panel = Label(root, image = img) 
panel.pack(side = "bottom", fill = "both", expand = "yes") 

#If i add this section the program goes awol-------------- 
app = Frame(root) 
app.grid() 
button1 = Button(app, text = "This is a button") 
button1.grid() 
#--------------------------------------------------------- 


#Start the event loop 
root.mainloop() 
+1

[按下按鈕交換接口(可能重複http://stackoverflow.com/questions/26298591/swap-interface-on-button-press) – jonrsharpe 2014-10-12 13:44:30

+0

*(** TL; DR **:請勿混合使用網格和包裝)* – jonrsharpe 2014-10-12 13:45:10

回答

2

的代碼混合packgrid

僅使用一個佈局管理器一次(至少對於誰共享相同的父窗口小部件)

... 
img = ImageTk.PhotoImage(Image.open("test.gif")) 
panel = Label(root, image = img) 
panel.pack(side="top", fill = "both", expand = "yes") 

app = Frame(root) 
app.pack(side='bottom') 
button1 = Button(app, text = "This is a button") 
button1.pack() 
... 
+0

謝謝!像魅力一樣工作。只是試圖用文字加 - 主= TK() W =標籤(主,文本=「你好,世界!」) w.pack(),但它創建了一個新的Tkinter窗口,我怎麼把它在同一? (p.s.不能得到代碼工作) – user3423572 2014-10-12 13:56:21

+0

@ user3423572,請將它作爲一個單獨的問題發佈。 – falsetru 2014-10-12 13:57:41

+0

這是我原來的問題的一部分,但沒問題 – user3423572 2014-10-12 13:59:21