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

  • @gloryness
    @gloryness4 жыл бұрын

    I always wondered how to do this - thanks for covering this :D

  • @Codemycom

    @Codemycom

    4 жыл бұрын

    sure thing!

  • @rushaan3039

    @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!

  • @bhoot1702
    @bhoot17022 жыл бұрын

    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

    @daraakojede342

    Жыл бұрын

    great, can i see a repo for that please?

  • @eshaangupta4101
    @eshaangupta41013 жыл бұрын

    Thanks a lot John, helped a lot!

  • @Codemycom

    @Codemycom

    3 жыл бұрын

    You're welcome!

  • @kalire9461
    @kalire9461 Жыл бұрын

    Thank You bro. That's so helped

  • @Codemycom

    @Codemycom

    Жыл бұрын

    Happy to hear it!

  • @RyanDanielG
    @RyanDanielG2 жыл бұрын

    Hit that like button Python Fans! Great tutorial. Feed the Algorithm!

  • @kashishrana4800
    @kashishrana48003 жыл бұрын

    Made a Bank Management app Using Tkinter. Thank you Sir for 5 hours course .Really Helpful❤

  • @Codemycom

    @Codemycom

    3 жыл бұрын

    Awesome, good job!

  • @sovereignlivingsoul
    @sovereignlivingsoul2 ай бұрын

    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

    @Codemycom

    2 ай бұрын

    Glad to hear it

  • @sheetalgupta1573
    @sheetalgupta15733 жыл бұрын

    thank you so much sir, this has helped me a lot in my gui

  • @Codemycom

    @Codemycom

    3 жыл бұрын

    Glad it helped!

  • @retroemfoco
    @retroemfoco2 жыл бұрын

    Thanks a lot, you help me so much!

  • @Codemycom

    @Codemycom

    2 жыл бұрын

    Happy to hear it!

  • @liopo9000
    @liopo90003 жыл бұрын

    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

    @Codemycom

    3 жыл бұрын

    Sure thing...there's about a hundred more tkinter videos on my channel too

  • @liopo9000

    @liopo9000

    3 жыл бұрын

    @@Codemycom I'm struggling with a proyect so I'll probably be checking them up shortly haha

  • @jawherballoumi6766
    @jawherballoumi6766 Жыл бұрын

    you are soo good keep up and thank you

  • @Codemycom

    @Codemycom

    Жыл бұрын

    Thanks!

  • @daltoncyr6145
    @daltoncyr61453 жыл бұрын

    the king of teaching python

  • @Codemycom

    @Codemycom

    3 жыл бұрын

    ha, thanks!

  • @luckeyduckey7858
    @luckeyduckey78582 жыл бұрын

    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

    @blankos1817

    2 жыл бұрын

    although its "ImageTk" and not "ImageTK", thanks man! i knew it had to be a shorter way to do this 😉😉

  • @bhoot1702

    @bhoot1702

    2 жыл бұрын

    I will try it thanks

  • @daraakojede342

    @daraakojede342

    Жыл бұрын

    @@blankos1817 hehe

  • @toplisttoday2284
    @toplisttoday22843 жыл бұрын

    Fantastic!!!

  • @Codemycom

    @Codemycom

    3 жыл бұрын

    Glad you liked it!

  • @rushaan3039
    @rushaan30393 жыл бұрын

    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

  • @munalatifi3757
    @munalatifi37573 жыл бұрын

    can u do one for video resizing? I wanna play videos inside a frame but the video sizes are inconsistent. thank you

  • @sebastianlandazurig8299
    @sebastianlandazurig82992 жыл бұрын

    Thanks !!!

  • @Codemycom

    @Codemycom

    2 жыл бұрын

    Welcome!

  • @sidhumm
    @sidhumm4 жыл бұрын

    Thanks a lot.

  • @Codemycom

    @Codemycom

    4 жыл бұрын

    Sure thing :-)

  • @rajivram9665
    @rajivram96653 жыл бұрын

    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)

  • @chococandy8009
    @chococandy80093 жыл бұрын

    Thank you so much sir :)

  • @Codemycom

    @Codemycom

    3 жыл бұрын

    Most welcome

  • @sakhshamchhibber1565
    @sakhshamchhibber15653 жыл бұрын

    Thanks sir Helped a lot in my school project

  • @Codemycom

    @Codemycom

    3 жыл бұрын

    You're welcome!

  • @eshaangupta4101
    @eshaangupta41013 жыл бұрын

    Keep making more videos!

  • @Codemycom

    @Codemycom

    3 жыл бұрын

    That's the plan!

  • @mohammedhoussemtoumi5545
    @mohammedhoussemtoumi55452 жыл бұрын

    You're a hero

  • @Codemycom

    @Codemycom

    2 жыл бұрын

    Ha, thanks!

  • @jeffkirchoff14
    @jeffkirchoff142 жыл бұрын

    Thx So Much For Solving my problem sir

  • @Codemycom

    @Codemycom

    2 жыл бұрын

    Happy to help!

  • @thiagoalvespinheiro8592
    @thiagoalvespinheiro85923 жыл бұрын

    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

  • @SarahTime.mp4
    @SarahTime.mp43 жыл бұрын

    The most satisfying feeling is when you finally get a code to work

  • @Codemycom

    @Codemycom

    3 жыл бұрын

    agreed

  • @GroockG
    @GroockG3 жыл бұрын

    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

    @Codemycom

    3 жыл бұрын

    Yeah, you have to use Pillow.

  • @angadsahu4152
    @angadsahu4152 Жыл бұрын

    Would it work with gif too??

  • @umeshdhoke5427
    @umeshdhoke54273 жыл бұрын

    Thank you sir for this video 😊😊😊😊 Your student from India 😊

  • @Codemycom

    @Codemycom

    3 жыл бұрын

    Welcome

  • @jmguezz3789
    @jmguezz37892 жыл бұрын

    Thank you sir..

  • @Codemycom

    @Codemycom

    2 жыл бұрын

    Very welcome!

  • @ozbekchawindows4236
    @ozbekchawindows42364 жыл бұрын

    You are so clever...

  • @Codemycom

    @Codemycom

    4 жыл бұрын

    Thanks

  • @balajir1586
    @balajir15863 жыл бұрын

    Sir please explain how to zoom in and zoom out browsed png image using tkinter

  • @bryanignacio2733
    @bryanignacio27332 жыл бұрын

    thanks :)

  • @Codemycom

    @Codemycom

    2 жыл бұрын

    Sure thing!

  • @martinwestin4539
    @martinwestin45393 жыл бұрын

    cool video. is there any way of resizing the image with the mouse (kind of like resizing images in google docs)?

  • @emre6714

    @emre6714

    6 ай бұрын

    have you figured out?

  • @abrarmulla1196
    @abrarmulla11963 жыл бұрын

    nice vid

  • @Codemycom

    @Codemycom

    3 жыл бұрын

    Thanks

  • @rsn_cs_itkotdwar6098
    @rsn_cs_itkotdwar609810 ай бұрын

    Can u sir help how to move image rotate in tkinter python

  • @israelcarvalho2167
    @israelcarvalho21673 жыл бұрын

    thanks!

  • @Codemycom

    @Codemycom

    3 жыл бұрын

    Welcome!

  • @KalyaniDesigns
    @KalyaniDesigns3 жыл бұрын

    oh thank u man

  • @Codemycom

    @Codemycom

    3 жыл бұрын

    You're welcome!

  • @arpitagec9
    @arpitagec93 жыл бұрын

    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

    @Codemycom

    3 жыл бұрын

    Just add them in the normal way. I have videos on images in the playlist.

  • @Sana-en9bp
    @Sana-en9bp3 жыл бұрын

    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

    @Codemycom

    3 жыл бұрын

    Use the same tools that I use.

  • @jutsuuchiha3858
    @jutsuuchiha38584 жыл бұрын

    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

    @Codemycom

    4 жыл бұрын

    Yeah exe's are a pain

  • @tomr9113
    @tomr91133 жыл бұрын

    I would like to know what editor you are using in this video. Thanks

  • @Codemycom

    @Codemycom

    3 жыл бұрын

    Sublime Text Editor and the Git bash git-scm.com terminal

  • @tomr9113

    @tomr9113

    3 жыл бұрын

    @@Codemycom Thank you

  • @Electrologia
    @Electrologia Жыл бұрын

    PLEASE, HELP ME. How can I save image after resizing? Please someone help me. :)

  • @TheGoldenPro
    @TheGoldenPro3 жыл бұрын

    Can someone help? I keep getting "AttributeError: '_io.TextIOWrapper' object has no attribute 'resize'" error.

  • @graysongarrett6739

    @graysongarrett6739

    3 жыл бұрын

    I'm getting the same error >.

  • @graysongarrett6739

    @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

  • @BeerTrooper
    @BeerTrooper3 жыл бұрын

    do you know why I'm getting "AttributeError: type object 'Image' has no attribute 'open'"

  • @Codemycom

    @Codemycom

    3 жыл бұрын

    probably a typo

  • @mohakjain7939
    @mohakjain79393 жыл бұрын

    plz help it is showing this error in my program self.tk.call( _tkinter.TclError: image "" doesn't exist

  • @Codemycom

    @Codemycom

    3 жыл бұрын

    does the image exist?

  • @Anish_88
    @Anish_884 жыл бұрын

    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

    @Codemycom

    4 жыл бұрын

    check your code for typos...

  • @sergionieto2405

    @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

    @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

    @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

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

  • @estudosacademicos5237
    @estudosacademicos52373 жыл бұрын

    Parabéns...

  • @Codemycom

    @Codemycom

    3 жыл бұрын

    Thank you

  • @antonsurviyanto5896
    @antonsurviyanto58964 жыл бұрын

    Tutorial how to insert text inside canvas Sir please, thank you

  • @Codemycom

    @Codemycom

    4 жыл бұрын

    Noted!

  • @AbysmalCCfoxcxz
    @AbysmalCCfoxcxz7 ай бұрын

    why am i getting this error: module 'PIL.Image' has no attribute 'ANTIALIAS'

  • @yasinsaleem2520

    @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

  • @shubhanshusharma5372
    @shubhanshusharma53723 жыл бұрын

    @Codemy pls help how to resize toplevel image

  • @Codemycom

    @Codemycom

    3 жыл бұрын

    In the same way you resize any image.

  • @shubhanshusharma5372

    @shubhanshusharma5372

    3 жыл бұрын

    @@Codemycom but it cant resized

  • @Codemycom

    @Codemycom

    3 жыл бұрын

    @@shubhanshusharma5372 yes it can

  • @codingstudio8865
    @codingstudio88653 жыл бұрын

    Sir, how to get the actual size of the image

  • @Codemycom

    @Codemycom

    3 жыл бұрын

    Try: image.width() and image.height()

  • @sivasurya4149
    @sivasurya41493 жыл бұрын

    Cute pic ....,,,,

  • @Codemycom

    @Codemycom

    3 жыл бұрын

    Thanks

  • @dukescompany7855
    @dukescompany78554 жыл бұрын

    Muito bom

  • @Codemycom

    @Codemycom

    4 жыл бұрын

    thanks

  • @nagendrasain9861
    @nagendrasain98613 жыл бұрын

    Getting an AttributeError: 'PhotoImage' object has no attribute 'resize'

  • @Codemycom

    @Codemycom

    3 жыл бұрын

    What did you do differently from the video?

  • @aayanomer6852
    @aayanomer68528 ай бұрын

    I don't know why but this resize is not working for me. it says that PhotoImage has no attribute resize.

  • @Codemycom

    @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

    @yasinsaleem2520

    15 күн бұрын

    newer versions of PIL have removed ANTIALIAS instead use Image.LANCZOS or Image. Resampling.LANCZOS hope this helps

  • @sarithnadeeja5234
    @sarithnadeeja52342 жыл бұрын

    💖💖💖💖💖💖💫🤟

  • @Codemycom

    @Codemycom

    2 жыл бұрын

    :-)

  • @sunirnaychatterjee8963
    @sunirnaychatterjee89634 жыл бұрын

    Please make tutorial videos on kivy because we can create android, iOS app using kivy but using tkinter we can't 😔 🙏🙏🙏🙏

  • @Codemycom

    @Codemycom

    4 жыл бұрын

    I'm planning on it

  • @marcosfonseca9478

    @marcosfonseca9478

    4 жыл бұрын

    I'm creating a app for Android with tkinter in Android

  • @favarobahamut6662
    @favarobahamut66623 жыл бұрын

    Why my resize didnt pop up

  • @Codemycom

    @Codemycom

    3 жыл бұрын

    You have a typo in your code

  • @vishalyewale4726
    @vishalyewale47263 жыл бұрын

    img1 = Image.Open("1.- Armani.png") AttributeError: type object 'Image' has no attribute 'Open'

  • @Codemycom

    @Codemycom

    3 жыл бұрын

    lowercase o in open

  • @Codemycom
    @Codemycom4 жыл бұрын

    ▶️ 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

  • @robinstejeda6273
    @robinstejeda62732 жыл бұрын

    It's very slow what hapen?

  • @Codemycom

    @Codemycom

    2 жыл бұрын

    What did you do differently than the video?

  • @G_a_n_d_u
    @G_a_n_d_u2 жыл бұрын

    please sir show me changing image size with scale .........please please please

  • @Codemycom

    @Codemycom

    2 жыл бұрын

    Doesn't this video show you how to resize any way you want? To do scale just do the math.

  • @shivam20095
    @shivam200952 жыл бұрын

    Nice Tutorial, But it is not working on my side

  • @Codemycom

    @Codemycom

    2 жыл бұрын

    Did you pip install Pillow?

  • @ssgoh4968
    @ssgoh49683 жыл бұрын

    How in the world does one know that there's a thing called Pillow without ever watching this video. :-)

  • @ashyvlogs1132
    @ashyvlogs11323 жыл бұрын

    Walter?

  • @Codemycom

    @Codemycom

    3 жыл бұрын

    Ha!

  • @unrevealed_hindi
    @unrevealed_hindiАй бұрын

    onepunch

  • @mujassimjamal24
    @mujassimjamal244 жыл бұрын

    First

  • @Codemycom

    @Codemycom

    4 жыл бұрын

    nice!