How To Resize Images With Tkinter - Python Tkinter GUI Tutorial #77
In this video I'll show you how to resize an Image with Tkinter.
Resizing images in Tkinter isn't as easy as you'd think. We need to use the Pillow library to open the image, then resize it, and then use it in a label or button or however you'd normally use it.
Пікірлер: 147
I always wondered how to do this - thanks for covering this :D
@Codemycom
4 жыл бұрын
sure thing!
@rushaan3039
3 жыл бұрын
Can you please make a video on how to add border in image and resize it like when u insert image in ms word and the one using the app can resize it from dragging its borders, it would be superb if u teach me that!
I needed this as I'm making an app for myself that converts images to any commonly used image formats that I downloaded from browsers. The problem was when I wanted to show a preview of the image selected for conversion. This video helped me a lot!
@daraakojede342
Жыл бұрын
great, can i see a repo for that please?
Thanks a lot John, helped a lot!
@Codemycom
3 жыл бұрын
You're welcome!
Thank You bro. That's so helped
@Codemycom
Жыл бұрын
Happy to hear it!
Hit that like button Python Fans! Great tutorial. Feed the Algorithm!
Made a Bank Management app Using Tkinter. Thank you Sir for 5 hours course .Really Helpful❤
@Codemycom
3 жыл бұрын
Awesome, good job!
this is most timely, i have a couple images in my program that i have been battling with to get the right size image, perfect
@Codemycom
2 ай бұрын
Glad to hear it
thank you so much sir, this has helped me a lot in my gui
@Codemycom
3 жыл бұрын
Glad it helped!
Thanks a lot, you help me so much!
@Codemycom
2 жыл бұрын
Happy to hear it!
bro i was looking your course on fCC and this was the only thing missing thank you very much for doing this follow up.
@Codemycom
3 жыл бұрын
Sure thing...there's about a hundred more tkinter videos on my channel too
@liopo9000
3 жыл бұрын
@@Codemycom I'm struggling with a proyect so I'll probably be checking them up shortly haha
you are soo good keep up and thank you
@Codemycom
Жыл бұрын
Thanks!
the king of teaching python
@Codemycom
3 жыл бұрын
ha, thanks!
you can simplify this to one line: new_pic = ImageTK.PhotoImage(Image.open("images/aspen.png").resize((300, 225), Image.ANTIALIAS)) you can do this if you want less lines of code for the resize
@blankos1817
2 жыл бұрын
although its "ImageTk" and not "ImageTK", thanks man! i knew it had to be a shorter way to do this 😉😉
@bhoot1702
2 жыл бұрын
I will try it thanks
@daraakojede342
Жыл бұрын
@@blankos1817 hehe
Fantastic!!!
@Codemycom
3 жыл бұрын
Glad you liked it!
Can you please make a video on how to add border in image and resize it like when u insert image in ms word and the one using the app can resize it from dragging its borders
can u do one for video resizing? I wanna play videos inside a frame but the video sizes are inconsistent. thank you
Thanks !!!
@Codemycom
2 жыл бұрын
Welcome!
Thanks a lot.
@Codemycom
4 жыл бұрын
Sure thing :-)
many thanks!! for some, if you get IMAGE class don't have type open error :( use this method, import PIL.ImageTk import PIL.Image #open image logo1=PIL.Image.open("pic1.png") #resize resized = logo1.resize((250,160),PIL.Image.ANTIALIAS) new_pic = PIL.ImageTk.PhotoImage(resized) logo_label = tk.Label(root,image = new_pic) logo_label.grid(row=0,column=0)
Thank you so much sir :)
@Codemycom
3 жыл бұрын
Most welcome
Thanks sir Helped a lot in my school project
@Codemycom
3 жыл бұрын
You're welcome!
Keep making more videos!
@Codemycom
3 жыл бұрын
That's the plan!
You're a hero
@Codemycom
2 жыл бұрын
Ha, thanks!
Thx So Much For Solving my problem sir
@Codemycom
2 жыл бұрын
Happy to help!
I have a question, I know how to put an image in a window, but when I click to change the window, the image does not open in another tkinter window
The most satisfying feeling is when you finally get a code to work
@Codemycom
3 жыл бұрын
agreed
Thanks for the great video, been trying to do this without using modules and just using Tk base code for ages, Should I be more welcoming to using modules like Pillow with python? or can you do this without Pillow?
@Codemycom
3 жыл бұрын
Yeah, you have to use Pillow.
Would it work with gif too??
Thank you sir for this video 😊😊😊😊 Your student from India 😊
@Codemycom
3 жыл бұрын
Welcome
Thank you sir..
@Codemycom
2 жыл бұрын
Very welcome!
You are so clever...
@Codemycom
4 жыл бұрын
Thanks
Sir please explain how to zoom in and zoom out browsed png image using tkinter
thanks :)
@Codemycom
2 жыл бұрын
Sure thing!
cool video. is there any way of resizing the image with the mouse (kind of like resizing images in google docs)?
@emre6714
6 ай бұрын
have you figured out?
nice vid
@Codemycom
3 жыл бұрын
Thanks
Can u sir help how to move image rotate in tkinter python
thanks!
@Codemycom
3 жыл бұрын
Welcome!
oh thank u man
@Codemycom
3 жыл бұрын
You're welcome!
Great tutorial! What if I want to have multiple images in the screen? Say 3 images in each row (3 rows), total=9 images. Please help me. TIA
@Codemycom
3 жыл бұрын
Just add them in the normal way. I have videos on images in the playlist.
I get a TclError "..." doesn't exist following what you did step by step and my directory is also correct. Can you help me with the problem please?
@Codemycom
3 жыл бұрын
Use the same tools that I use.
I made an image editor with PIL with some edit options and Tkinter and my error gets in where to pack it as an .exe Hell it compiles when I run the file it's shows error. Kaboom
@Codemycom
4 жыл бұрын
Yeah exe's are a pain
I would like to know what editor you are using in this video. Thanks
@Codemycom
3 жыл бұрын
Sublime Text Editor and the Git bash git-scm.com terminal
@tomr9113
3 жыл бұрын
@@Codemycom Thank you
PLEASE, HELP ME. How can I save image after resizing? Please someone help me. :)
Can someone help? I keep getting "AttributeError: '_io.TextIOWrapper' object has no attribute 'resize'" error.
@graysongarrett6739
3 жыл бұрын
I'm getting the same error >.
@graysongarrett6739
3 жыл бұрын
i had two problems i needed to solve Before: my_img = ImageTk.PhotoImage(Image.open("A1f.png")) image_label = Label(image=my_img, height=150, width=150) After: my_img = Image.Open('A1f.png') image_label = Label(image=new_pic, height=150, width=150) Hope this helps
do you know why I'm getting "AttributeError: type object 'Image' has no attribute 'open'"
@Codemycom
3 жыл бұрын
probably a typo
plz help it is showing this error in my program self.tk.call( _tkinter.TclError: image "" doesn't exist
@Codemycom
3 жыл бұрын
does the image exist?
Im trying this way But with any size I run it shows a white window there is no pictures Or maybe the size is too high or ....?
@Codemycom
4 жыл бұрын
check your code for typos...
@sergionieto2405
3 жыл бұрын
Hi, i have the same problem, i get the path of the images but only a white box is displayed, could you solve it?
@Anish_88
3 жыл бұрын
Yeah but if we try to see a picture in that We have to type a mistake text in the end and that time we can see our called pictures
@sergionieto2405
3 жыл бұрын
@@Anish_88 then how can I solve that?, in this moment is very important for me, I have the path of some image, there is when fail and I have only the label with it background, but I need the image that im calling with the path :/, really need help
@nuradibahaqilah4008
3 жыл бұрын
First check your code.. if exactly same you should try use global my_image... it also happen to me but after i apply it.. its works!!! example my code: def open(): global my_image #Global variables can be used by everyone root.filename = filedialog.askopenfilename(initialdir=os.getcwd(), title="Select Image File", filetypes=(("JPG File","*.jpg"),("PNG file","*.png"),("All Files", "*.*"))) my_image = Image.open(root.filename) resized = my_image.resize((200, 200), Image.ANTIALIAS) #resize and get quality image my_image = ImageTk.PhotoImage(resized) my_label = Label(imageframe, image=my_image).pack()
Parabéns...
@Codemycom
3 жыл бұрын
Thank you
Tutorial how to insert text inside canvas Sir please, thank you
@Codemycom
4 жыл бұрын
Noted!
why am i getting this error: module 'PIL.Image' has no attribute 'ANTIALIAS'
@yasinsaleem2520
15 күн бұрын
i know this is late but newer versions of PIL have removed ANTIALIAS instead use Image.LANCZOS or Image. Resampling.LANCZOS hope this helps
@Codemy pls help how to resize toplevel image
@Codemycom
3 жыл бұрын
In the same way you resize any image.
@shubhanshusharma5372
3 жыл бұрын
@@Codemycom but it cant resized
@Codemycom
3 жыл бұрын
@@shubhanshusharma5372 yes it can
Sir, how to get the actual size of the image
@Codemycom
3 жыл бұрын
Try: image.width() and image.height()
Cute pic ....,,,,
@Codemycom
3 жыл бұрын
Thanks
Muito bom
@Codemycom
4 жыл бұрын
thanks
Getting an AttributeError: 'PhotoImage' object has no attribute 'resize'
@Codemycom
3 жыл бұрын
What did you do differently from the video?
I don't know why but this resize is not working for me. it says that PhotoImage has no attribute resize.
@Codemycom
8 ай бұрын
Check your code vs the video to see what you did differently from the video. You likely missed something or have a typo.
@yasinsaleem2520
15 күн бұрын
newer versions of PIL have removed ANTIALIAS instead use Image.LANCZOS or Image. Resampling.LANCZOS hope this helps
💖💖💖💖💖💖💫🤟
@Codemycom
2 жыл бұрын
:-)
Please make tutorial videos on kivy because we can create android, iOS app using kivy but using tkinter we can't 😔 🙏🙏🙏🙏
@Codemycom
4 жыл бұрын
I'm planning on it
@marcosfonseca9478
4 жыл бұрын
I'm creating a app for Android with tkinter in Android
Why my resize didnt pop up
@Codemycom
3 жыл бұрын
You have a typo in your code
img1 = Image.Open("1.- Armani.png") AttributeError: type object 'Image' has no attribute 'Open'
@Codemycom
3 жыл бұрын
lowercase o in open
▶️ Watch Entire Tkinter Playlist ✅ Subscribe To My KZread Channel: bit.ly/2UFLKgj bit.ly/2IGzvOR ▶️ See More At: ✅ Join My Facebook Group: Codemy.com bit.ly/2GFmOBz ▶️ Learn to Code at Codemy.com ✅ Buy a Codemy T-Shirt! Take $30 off with coupon code: youtube1 bit.ly/2VC9WUN
It's very slow what hapen?
@Codemycom
2 жыл бұрын
What did you do differently than the video?
please sir show me changing image size with scale .........please please please
@Codemycom
2 жыл бұрын
Doesn't this video show you how to resize any way you want? To do scale just do the math.
Nice Tutorial, But it is not working on my side
@Codemycom
2 жыл бұрын
Did you pip install Pillow?
How in the world does one know that there's a thing called Pillow without ever watching this video. :-)
Walter?
@Codemycom
3 жыл бұрын
Ha!
onepunch
First
@Codemycom
4 жыл бұрын
nice!