История изменений
Исправление lucentcode, (текущая версия) :
Ну, вы же только очень малую часть кода выложили. Выложите весь код, что отвечает за создание окна и отрисовку изображения.
К примеру, у меня такой вот пример
#!/usr/bin/env python
"""
Will test using canvas and Pillow to open a jpg image, and handle mouse click events
"""
from tkinter import *
from PIL import ImageTk, Image
class PhotoCanvas(Frame):
def __init__(self,master=None):
"""Sets up window and widgets"""
Frame.__init__(self)
self.master.title("Test")
# opens the photo and convert them to Tkinter-compatible image objects
self.image1 = Image.open("test.jpg")
self.photo = ImageTk.PhotoImage(self.image1)
# returns tuple of width and height of image
(iWidth, iHeight) = self.image1.size
# create a canvas and place in frame
self.canvas = Canvas(self, width = iWidth, height = iHeight)
self.canvas.pack(side="top", fill="both", expand=True)
# places image in upper left corner (NW) on the canvas at x=0, y=0
self.canvas.create_image(0, 0, image=self.photo, anchor=NW)
root = Tk()
ui = PhotoCanvas(root)
ui.pack(side="top", fill="both", expand=True)
ui.mainloop()
отлично работает. Ну и пример из https://pythonprogramming.net/tkinter-adding-text-images/ вроде тоже рабочий.
Исходная версия lucentcode, :
Ну, вы же только очень малую часть кода выложили. Выложите весь код, что отвечает за создание окна и отрисовку изображения.
К примеру, у меня такой вот пример
#!/usr/bin/env python
"""
Will test using canvas and Pillow to open a jpg image, and handle mouse click events
"""
from tkinter import *
from PIL import ImageTk, Image
class PhotoCanvas(Frame):
def __init__(self,master=None):
"""Sets up window and widgets"""
Frame.__init__(self)
self.master.title("Test")
# opens the photo and convert them to Tkinter-compatible image objects
self.image1 = Image.open("test.jpg")
self.photo = ImageTk.PhotoImage(self.image1)
# returns tuple of width and height of image
(iWidth, iHeight) = self.image1.size
# create a canvas and place in frame
self.canvas = Canvas(self, width = iWidth, height = iHeight)
self.canvas.pack(side="top", fill="both", expand=True)
# places image in upper left corner (NW) on the canvas at x=0, y=0
self.canvas.create_image(0, 0, image=self.photo, anchor=NW)
root = Tk()
ui = PhotoCanvas(root)
ui.pack(side="top", fill="both", expand=True)
ui.mainloop()
Отлично работает. Ну и пример из https://pythonprogramming.net/tkinter-adding-text-images/ вроде тоже рабочий.