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?
#9
(Apr-05-2019, 04:26 PM)wuf Wrote: Hi jpezz

You can't place a Canvas directly on the screen. It must be embedded on the main window. Here some different placements of an image in a tk-Application:

[/python]wuf :-)
Great! Wonderful explanation of the choices and I can easily change the numbers so that canvas and move to different positions Since I have used the label widget before (but don't yet fully understand it), I'd prefer not to have to have a canvas. I played around with your program and I see how I can move things around.
My objective would be to put out a single letter in the Label but it would be big enough for multiple letters. Then I would, in a function, update the label to add an additional letter. I tried just simply creating the label then updating it in the mainloop so this:
# Create a label widget containig the image and place it directly on
# the main window
image_label = tk.Label(root, text="Image Label placed\non main window",
    compound='bottom', image=root.test_image)
image_label.place(x=500, y=50)
looks like this now:
# Create a label widget containig the image and place it directly on
# the main window
image_label = tk.Label(root, text="Image Label placed\non main window",
    compound='bottom', image=root.test_image)
image_label.place(x=500, y=50)

image2 = Image.open("pngs/b.png")
root.test_image = ImageTk.PhotoImage(image2)
image_label.place(x=600, y=50)
image_label.config (root,image=root.test_image)
and I get this error.
Quote:Traceback (most recent call last):
File "his_original.py", line 58, in <module>
root.place(x=600, y=50)
File "/usr/lib/python3.6/tkinter/__init__.py", line 2101, in __getattr__
return getattr(self.tk, attr)
AttributeError: '_tkinter.tkapp' object has no attribute 'place'

Fumbling my way through python one error at a time.
Reply


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

Possibly Related Threads…
Thread Author Replies Views Last Post
  Switching from tkinter to gtk is difficult! snakes 1 1,505 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