使用tkinter

时间:2017-12-02 13:33:14

标签: python-3.x tkinter

import tkinter
from tkinter import *
from PIL import Image

root = tkinter.Tk()
photo = tkinter.PhotoImage(file="two.png")
cv = tkinter.Canvas()  
cv.pack(side='top', fill='both', expand='yes')  
cv.create_image(0, 0, image=photo, anchor='nw')  
root.mainloop()

代码显示png文件但是当我用jpg文件替换png文件时,它无法显示它给出以下错误,

Traceback (most recent call last):
  File "C:/Users/DB/AppData/Local/Programs/Python/Python35/Python Code/img_disp.py", line 6, in <module>
    photo = tkinter.PhotoImage(file="two1.jpg")
  File "C:\Users\DB\AppData\Local\Programs\Python\Python35\lib\tkinter\__init__.py", line 3402, in __init__
    Image.__init__(self, 'photo', name, cnf, master, **kw)
  File "C:\Users\DB\AppData\Local\Programs\Python\Python35\lib\tkinter\__init__.py", line 3358, in __init__
    self.tk.call(('image', 'create', imgtype, name,) + options)
_tkinter.TclError: couldn't recognize data in image file "two1.jpg"

我想在使用tkinter创建的UI中显示具有特定宽度和高度的jpg图像。请指导......

0 个答案:

没有答案