栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Python图像显示

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Python图像显示

为此目的使用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,请继续修改该示例,它不会花费太多。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/596484.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号