【发布时间】:2014-12-07 04:15:23
【问题描述】:
我正在创建一个启动画面,作为我的程序的介绍。我已经设法在屏幕上放置了一个图像,但是一旦我添加了一个按钮,什么都没有出现,甚至没有 tkinter 窗口。
我想要做的是在窗口顶部有一个图像,在它下面有一个我的名字“Bob Johns”的文本框,然后是另一个按钮,上面写着"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()
【问题讨论】:
-
(TL;DR:不要混用
grid和pack)
标签: python image python-2.7 button tkinter