为此目的使用Tkinter和PIL非常简单。将muskies示例添加到包含此示例的该线程的信息中:
# use a Tkinter label as a panel/frame with a background image# note that Tkinter only reads gif and ppm images# use the Python Image Library (PIL) for other image formats# free from [url]http://www.pythonware.com/products/pil/index.htm[/url]# give Tkinter a namespace to avoid conflicts with PIL# (they both have a class named Image)import Tkinter as tkfrom PIL import Image, ImageTkroot = tk.Tk()root.title('background image')# pick an image file you have .bmp .jpg .gif. .png# load the file and covert it to a Tkinter image objectimageFile = "Flowers.jpg"image1 = ImageTk.PhotoImage(Image.open(imageFile))# get the image sizew = image1.width()h = image1.height()# position coordinates of root 'upper left corner'x = 0y = 0# make the root window the size of the imageroot.geometry("%dx%d+%d+%d" % (w, h, x, y))# root has no image argument, so use a label as a panelpanel1 = tk.Label(root, image=image1)panel1.pack(side='top', fill='both', expand='yes')# put a button on the image panel to test itbutton2 = tk.Button(panel1, text='button2')button2.pack(side='top')# save the panel's image from 'garbage collection'panel1.image = image1# start the event looproot.mainloop()
当然,如果您更熟悉另一个GUI,请继续修改该示例,它不会花费太多。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)