Python GUI Tutorial - 16 - Canvas - create image | Tkinter

preview_player
Показать описание
In this video, you're going to learn how we can create image or draw image on a canvas in tkinter.

so i'm sure your queries like -

- how we can create image on canvas in tkinter?
- how to draw an image in tkinter canvas?
- what is anchor in image canvas tkinter?
-anchor in create image in Tkinter canvas?
- explanation of anchor in create image in tkinter?
- what is arguments that create_image method of canvas in tkinter took?

have been solved.

if you still have a problem related with this video or in tkinter, please let us know in comment box.

Рекомендации по теме
Комментарии
Автор

English speaker here... totally understandable video! Thanks!

donnadietz
Автор

Sometimes the image might be bigger than the size of canvas, then this process will crop the image. To get around this you have to use PIL. First install pillow from cmd prompt via: pip install pillow

Then use this code:

from tkinter import *
from PIL import Image
from PIL import ImageTk

root = Tk()

canvas = Canvas(root, width=200, height=200, bg='lightgray') #drawing canvas
canvas.pack()

#to insert image with width = 100 and height =100
width = 100
height = 100
img = #this will open image
img = img.resize((width, height), Image.ANTIALIAS) #this will resize image. Image.ANTIALIAS will help to mantain aspect ratio

PhotoImg = ImageTk.PhotoImage(img) #Will convert it into tkinter image format
canvas.create_image(0, 0, image=PhotoImg, anchor='nw')

root.mainloop()

pran
Автор

You are the best teacher in the whole world 😃👌👌👍

shivnandan
Автор

Thank you very much. Keep making these videos

varungaur
Автор

How to add text beside the image because when I tired doing that it disappeared behind the canvas

Firstname-eiil
Автор

bro // ki jagh per small r use kiya karo is se path le lega ex = file=r"file path " like this

dontblinkmen
Автор

sir mere me error aarhi he plzz solve my error (most recent call last):
File "C:/Users/lenovo/PycharmProjects/pythonProject4/image.py", line 1, in <module>
from tinker import *
ModuleNotFoundError: No module named 'tinker'
sir this the

mansisoni
Автор

it's showing an error that :name 'canvas' is not defined

celdorufus
Автор

Hii I'm trying to insert an image in my windows pc, using pycharm but an error is coming every time, it states
Unicode error,

rajpant
Автор

bro how to save that image with canvas

wakkendul
Автор

My selected image is bigger than the canvas size. Dear sir please tell me how how to show full image inside this canvas.

manojkumarmahalik
Автор

amazing video, now how can i export the result as png or eps?

welidbenchouche
Автор

Mujhe Full image chahiye image badi kese hogi

Ritikabathaw
Автор

hi ive been following your tutorials alot and they help me so much.i am stuck at an issue: i want to play a video mp4 format file inside this canvas instead of showing image file. can u help

zeesh
Автор

image couldn't open in my program ... as it says _tkinter.TclError: couldn't open 'c://users//Jai yadav// Pictures//screenshot'): no such file or directory

jaiyadav
Автор

Sir how we can add simply text on the background image and change text properties

sukhmeetsingh
Автор

Hi Sir, I have syntax error:(unicode error) 'unicodeescape' codec can't decode bytes in position 3-4: truncated escape.how it resolved.???

seemachaskar
Автор

is there anyway to add two images at the same time

Better.Aim.
Автор

Windows users have backward slash in location path compared to Mac which have forward slash. So how to insert the image by copying the location? I'm getting error. Tried everything

SuplexCityF
Автор

I literally copy the code and it just creates a blank window, using a png file. I don't get it.

petrockspiracy