4
這隻顯示圖像的右下角。我究竟做錯了什麼?python tkinter:只顯示圖像的一部分
from Tkinter import *
from PIL import Image, ImageTk
class Application(Frame):
def __init__(self, titl, master=None):
Frame.__init__(self, master)
self.grid()
self.create_widgets()
self.master.title(titl)
def create_widgets(self):
image_file = 'sample.jpg'
image1 = ImageTk.PhotoImage(Image.open(image_file))
w = image1.width()
h = image1.height()
self.canvas = Canvas(self, width=w+5, height=h+5)
self.canvas.grid(row=0, column=0)
self.canvas.create_image(0,0, image=image1)
self.canvas.image = image1
app = Application('Image')
app.mainloop()
參見例如對於tkinter + PIL示例http://code.activestate.com/recipes/521918-pil-and-tkinter-to-display-images/ –
爲什麼要標籤工作,但不是畫布? – foosion