python在tk界面播放视频_如何在python2.7中使用tk在gui上显示图像

这篇博客介绍了如何在Tkinter GUI应用中显示图像。通过创建一个Tkinter窗口,加载图片并使用PhotoImage对象,然后在Canvas组件上放置图片,实现了在GUI界面上展示图像的功能。代码示例中展示了如何加载GIF图像并将其显示在窗口顶部的Canvas上。
摘要由CSDN通过智能技术生成

1586010002-jmsa.png

i need away to be able to show an image when i run the python code in its gui form if possible. Also do i have to type in the folder name and file name in the code if you know the answer i tried pil all it did was save the image into a folder i want this on the gui

the code for the tk if it is necessary

from Tkinter import *

root = Tk()

toolbar = Frame(root)

# All the buttons in my program

b = Button(toolbar, text="Home", width=9)

b.pack(side=LEFT, padx=2, pady=2)

b = Button(toolbar, text="About-us", width=9)

b.pack(side=LEFT, padx=2, pady=2)

b = Button(toolbar, text="Contact-us", width=9)

b.pack(side=LEFT, padx=2, pady=2)

b = Button(toolbar, text="Travelling", width=9)

b.pack(side=LEFT, padx=2, pady=2)

toolbar.pack(side=TOP, fill=X)

# All the labels in my program

o = Label(root,text="Frank Anne",font =("Italic",18,"bold"))

o.pack()

toolbar1 = Frame(root)

o=Label(root,)

o.pack()

o=Label(root,text ="Age: 27")

o.pack()

o=Label(root,text ="Address: 71 strawberry lane, JU8 8TY")

o.pack()

toolbar1.pack(side=BOTTOM, fill=X)

mainloop()

解决方案

Hello if your looking to show an image inside a tk Canvas it needs to be a PPM/PGM or GIF:

discussion from python.org

However if your looking to load a PPM, PGM or GIF:

import Tkinter as tk

root = tk.Tk()

root.title("display a website image")

photo = tk.PhotoImage(file= r"C:\Some\Local\location\smile.gif")

cv = tk.Canvas()

cv.pack(side='top', fill='both', expand='yes')

cv.create_image(10, 10, image=photo, anchor='nw')

root.mainloop()

This creates a frame, loads the image using tk.PhotoImage, then makes a canvas and puts the image onto the canvas.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值