Page Nav

HIDE

Left Sidebar

TO-LEFT

Breaking News

latest

How to add images in tkinter - Full explained?

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 = Tk() After this our code start.

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")

photo1 = PhotoImage(file="hello.png") the photo1 is a variable and PhotoImage is a widget if you don't know what is widget you can watch this video. and learn what is widget and trust me this is not any type of promotion and also it is not my video. let's back to the point and file="hello.png" is we have given the name of the file.

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")

image = Image.open("photo.jpg") is used used to load the image in python code but we have not put the image on GUI.

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()

root.mainloop() under this we write all the codes.

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