Python Forum
[Tkinter] Why is it so difficult to just ouput an image where I want?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Why is it so difficult to just ouput an image where I want?
#7
(Apr-05-2019, 01:19 PM)wuf Wrote: Hi jpezz

You have to bind the tk-image to an object. In your case for instance to the object root. The canvas needs a layout membership for which i choosed pack. For the canvas.create_image add for instance the option anchor='nw'. So the x/y-coordinates relate to the upper left corner of the image. In your case the image would be place outsite of the visuable surface of the canvas:

from Tkinter import *
from PIL import Image, ImageTk
 
root = Tk()
# Remove titlebar    
#root.overrideredirect(1)
canvas = Canvas(root, width =200,height=200)
canvas.pack()
image = Image.open("pngs/a.jpg")
#logo=PhotoImage(file="pngs/a.jpg)
root.logo = ImageTk.PhotoImage(image)

canvas.create_image(10, 10, image=root.logo, anchor='nw')

root.mainloop()
wuf :-)

I got it! I misunderstood the coordinates in the canvas.create_image statement. I thought it was the POSITION of the canvas in the window. Instead I was locating the image outside the canvas. However, I would like to position the canvas in a specific location. I found nothing on that but did find something on Label so I tried this:
canvas.place(x=50,y=100)
but it doesn't work. How can I position the canvas itself on the screen?
Reply


Messages In This Thread
RE: Why is it so difficult to just ouput an image where I want? - by jpezz - Apr-05-2019, 02:33 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Switching from tkinter to gtk is difficult! snakes 1 1,558 Aug-08-2022, 10:35 PM
Last Post: woooee

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020