Adding Images In Python
How do you add images in Python?
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 :
from tkinter import *
Create the window using Tk class:
root = Tk()
Create a cavas and pass in the width, height parameters:
canvas = Canvas(root, width = 700, height = 700) canvas.pack()
Add an image file, only works with pngs:
img = PhotoImage(file="amongus.png") canvas.create_image(20,20, anchor=NW, image=img) mainloop()
And run the window using
mainloop(). Now, you will have your image displayed on a UI interface:
Hope this helped :P :D :) :}