close

How to insert an image in a canvas item?

Hello Guys, How are you all? Hope You all Are Fine. Today We Are Going To learn about How to insert an image in a canvas item in Python. So Here I am Explain to you all the possible Methods here.

Without wasting your time, Let’s start This Article.

Table of Contents

How to insert an image in a canvas item?

  1. How to insert an image in a canvas item?

    from tkinter import * # create the canvas, size in pixels canvas = Canvas(width=300, height=200, bg='black')

  2. insert an image in a canvas item

    from tkinter import * # create the canvas, size in pixels canvas = Canvas(width=300, height=200, bg='black')

Method 1

from tkinter import *

# create the canvas, size in pixels
canvas = Canvas(width=300, height=200, bg='black')

# pack the canvas into a frame/form
canvas.pack(expand=YES, fill=BOTH)

# load the .gif image file
gif1 = PhotoImage(file='small_globe.gif')

# put gif image on canvas
# pic's upper left corner (NW) on the canvas is at x=50 y=10
canvas.create_image(50, 10, image=gif1, anchor=NW)

# run it ...
mainloop()

Summery

It’s all About this issue. Hope all Methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which Method worked for you? Thank You.

Also, Read