python tkinter: displays only a portion of an image -
It only shows the bottom right corner of my image Is I doing the wrong thing? PIL import image, from DTIT __int (___ (self, titel, master = none) from the imagetech class application (frame) to Tkinter import * from
: frame .__ init __ (self, master) Self.grid () self.create_widgets () self.master.title (titl) def create_widgets (auto): 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 (line = 0, column = 0) self.canvas.create_image ( 0,0, image = image1) self.canvas.image = image1 app = application ('image') app Menloop ()
You nw Setting is required because it has the value of CENTER by default, as the names are suggested by the name Image on the given coordinate: self.canvas.create_image (0,0, image = image1, anchor = nw) Or you can change if you keep the image ID later:
self .idIm age = self.canvas.create_image (0,0, image = image1) ... self.canvas.itemconfig (self.idImage, anchor = NW)
Comments
Post a Comment