Ask coding questions

← Back to all posts
Adding Images In Python
MisterMr

How do you add images in Python?

Answered by OldWizard209 [earned 5 cycles]
View Answer
Voters
MisterMr
Comments
hotnewtop
OldWizard209

You can't add images directly in Python because it is a console-based language and you can't add images on the console directly. So rather, you will have to use Python's Tkinter Framework.

Lemme quickly overview how can you get an image to show in Tkinter.
Import Tkinter :

Create the window using Tk class:

Create a cavas and pass in the width, height parameters:

Add an image file, only works with pngs:

And run the window using mainloop(). Now, you will have your image displayed on a UI interface:

Hope this helped :P :D :) :}