Python Forum
question on tkinter canvas PhotoImage
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
question on tkinter canvas PhotoImage
#1
I want to put an image in a window above the buttons.
but the window is blank where the canvas is supposed to be.?

from tkinter import *
from PIL import ImageTk,Image
root = Tk()
root.geometry("480x480")
root.title("planets")
label =Label(root , text = "what planet would you like to know about?")
label.grid(row =15 , column = 1)

canvas = Canvas(root , width = 200 , height = 200)
canvas.grid(row = 10 , column = 3 )

photo = PhotoImage('gif.gif')
canvas.create_image(0,0 , anchor = NW, image = photo)

root.mainloop()
Reply
#2
add a frame, and/or panel directly on root window that spans entire window space.
(if you use both frame and panel (good practice), then create you other widgets, all on the Panel
Using this method, you will have complete control of where the widgets appear on the screen.

By the way, this reference manual is very useful, if you don't already have a copy:
http://reu.cct.lsu.edu/documents/Python_...kinter.pdf
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] question for a tkinter dialog box RobertAlvarez424 2 187 Aug-25-2021, 03:08 PM
Last Post: RobertAlvarez424
  [Tkinter] Clickable Rectangles Tkinter Canvas MrTim 4 1,163 May-11-2021, 10:01 PM
Last Post: MrTim
  [Tkinter] Draw a grid of Tkinter Canvas Rectangles MrTim 5 931 May-09-2021, 01:48 PM
Last Post: joe_momma
Thumbs Up tkinter canvas; different page sizes on different platforms? philipbergwerf 4 844 Mar-27-2021, 05:04 AM
Last Post: deanhystad
  Python tkinter question tablet Nick_tkinter 8 1,366 Mar-04-2021, 10:44 PM
Last Post: Larz60+
  tkinter slider question Nick_tkinter 1 587 Feb-22-2021, 01:31 PM
Last Post: deanhystad
  how to resize image in canvas tkinter samuelmv30 2 4,176 Feb-06-2021, 03:35 PM
Last Post: joe_momma
  [Tkinter] Noob question:Using pyttsx3 with tkinter causes program to stop and close, any ideas? Osman_P 4 2,179 Nov-14-2020, 10:51 AM
Last Post: Osman_P
  how to rotate lines in tkinter canvas helpmewithpython 1 1,117 Oct-06-2020, 06:56 PM
Last Post: deanhystad
  Tkinter function to clear old canvas and start a fresh "operation" zazas321 5 2,134 Oct-01-2020, 04:16 AM
Last Post: zazas321

Forum Jump:

User Panel Messages

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