Search code examples
pythontkinterphotoimage

Python: Whole image not showing


Today I was trying to learn how the PhotoImage works but I run into errors and problems non stop. After lots of research I finally get an image to show up BUT its not the whole image, just a piece of it.

Heres my code:

from tkinter import*

root = Tk()
canvas = Canvas( root , width=720 , height=480 )
originallogo = PhotoImage( file="Picture1.gif" )
canvas.create_image( 0, 0, image=originallogo )
canvas.grid()
root.mainloop()

I would post a screenshot of the outcome but I am not level 10 yet. Heres a link of it instead: https://www.dropbox.com/s/iiwsdmgvlhyhlef/Screen%20shot%202014-11-24%20at%208.34.51%20PM.png?dl=0


Solution

  • By default the center of the image will be placed at the given coordinates. If you want the upper left corner of the image to be at 0,0, add anchor="nw"

    canvas.create_image(..., anchor="nw", ...)