Importing Image/s in python | Sololearn: Learn to code for FREE!

0

Importing Image/s in python

How do you add an image in python

9/15/2019 4:53:16 PM

Josh

2 Answers

New Answer

+3

Use Tkinter module from tkinter import * # pip install pillow from PIL import Image, ImageTk class Window( Frame ) : def __init __ ( self , master= None ) : Frame . __init __(self , master) self . master = master self . pack ( fill = BOTH , expand= 1 ) load = Image . open ( " Koder. jpg" ) render = ImageTk . PhotoImage ( load ) img = Label ( self , image= render) img. image = render img. place ( x = 0 , y = 0 ) root = Tk() app = Window( root ) root . wm_ title ( " Tkinter window" ) root . geometry( " 200x 120" ) root . mainloop()

0

#Pygame does it shorter: import pygame_sdl2 as pygame pygame.init() image = pygame.image.load("smile.jpg") surface = pygame.display.set_mode(image.get_size()) surface.blit(image, image.get_rect()) pygame.display.flip() pygame.time.delay(5000) pygame.quit()