In this video we’ll learn how to add Images to our apps with Tkinter and Python.
Generally, to add an image to your TKinter app you’ll create a label, and then add the image to the label.
We’ll use the PIL (Python Imaging Library) to add the image to our app and I’ll also show you how to resize the image.
Python Code: images.py
(Github Code)
from tkinter import * from PIL import ImageTk, Image root = Tk() root.title("Images - Intro To Tkinter") root.iconbitmap('images/tkinter.ico') root.geometry('600x400') # Create our image aspen = Image.open("images/aspen.png").resize((250,188)) aspen = ImageTk.PhotoImage(aspen) # Create a label my_label = Label(root, image=aspen, bd=2, relief="groove") #raised, ridge, sunken, groove, flat my_label.pack(pady=20) # Create a button Image login = Image.open("images/login.png").resize((75,30)) login = ImageTk.PhotoImage(login) # Create a button my_button = Button(root, image=login, bd=0) my_button.pack(pady=20) root.mainloop()
Add comment