How to add images in tkinter? To add images in tkinter we have to simply write this code to make a image GUI . There are two ways we cannot...
How to add images in tkinter?
To add images in tkinter we have to simply write this code to make a image GUI .There are two ways we cannot add .jpg images in tkinter We have to use pillow module to add jpg images.
"""
from tkinter import *
from PIL import Image, ImageTk
root = Tk()
root.geometry("1034x964")
photo1 = PhotoImage(file="hello.png")
l1=Label(image=photo1)
l1.pack()
# For image .jpg
image = Image.open("photo.jpg")
photo1 = ImageTk.PhotoImage(image)
l2 = Label(image=photo)
l2.pack()
root.mainloop()
"""
For more understanding we have to understand this code perfectly.
For .png way
from tkinter import *
from tkinter import * is used for importing every thing from tkinter.
from PIL import Image, ImageTk
from PIL import Image, ImageTk is used for importing image,imageTk from pillow module.
root = Tk()
root.geometry("1034x964")
root.geometry("1255x944") it is used to define the width and height of the of our GUI window.
photo1 = PhotoImage(file="hello.png")
l1=Label(image=photo1)
l1=Label(image=photo1) is used to we are using label if you don't know label you can watch this video. now back to the topic now we are choosing image now the image is photo1.
l1.pack()
We are packing the l1 and putting it in GUI.
For .jpg image
image = Image.open("photo.jpg")
photo1 = ImageTk.PhotoImage(image)
photo1 = ImageTk.PhotoImage(image) now we are choosing the image.
l2 = Label(image=photo)
l2 = Label(image=photo) now we are choosing the image in label.
l2.pack()
l2.pack() now we are packing the image.
root.mainloop()
Conclusion
Now you have seen that how to add multiple images in tkinter and for not missing our more valuable content bookmark our website by clicking on top right star button and bookmark our website in this blog.
And if you don't know we have a website for downloading thumbnail of youtube which help the youtubers for putting thumbnail of there old videos on there video the website link is proyoutubethumbnail.in.
And our second website is to translating audio to text audiototextbest.blogspot.com it is used for translating audio to text in english or in hindi.
And our third website is to download the youtube videos and youtube to mp3 this is the best website for downloading youtube videos website is promp3videodownloader.blogspot.com.
By Nikunj Gupta
By technical-gyan-double.blogspot.com
No comments