Using Icons, Images, and Exit Buttons - Python Tkinter GUI Tutorial #8

Поділитися
Вставка
  • Опубліковано 22 січ 2025

КОМЕНТАРІ • 757

  • @Codemycom
    @Codemycom  4 роки тому +10

    ▶️ Watch Entire Tkinter Playlist ✅ Subscribe To My UA-cam 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

    • @jainajit2412
      @jainajit2412 4 роки тому

      how to display multiple images in tkinter window. I have tried this code but its not working!
      from tkinter import *
      import os
      root = Tk()
      root.geometry('1000x600+180+50')
      list_img=[]
      for i in os.listdir():
      if i.split('.')[1] == 'png':
      list_img.append(i)
      f1 = Frame(root,bg='black',borderwidth=5 ,relief=SUNKEN,)
      f1.pack(fill=BOTH)
      for image in range(0,9):
      photo_ = PhotoImage(file=list_img[image])
      img_ = photo_.subsample(2,2)
      l = Label(f1,image=img_)
      l.pack(pady=5)
      root.mainloop()

    • @donaldppaul3260
      @donaldppaul3260 3 роки тому

      There is a bug in my calculator .if we press equal to again after a mathametical operation it just do that same mathametical operation with result
      I mean is that a bug

    • @100jsj6
      @100jsj6 3 роки тому

      @Codemy.com Hello sir ,I have an error : i cant really add the icon . i dont know why . heres what i did :
      root.iconbitmap(C:\Users\myuser\Desktop\Coding-Items\image.ico)
      # this doesnt work . can you give me suggestion ?
      Thanks

    • @Codemycom
      @Codemycom  3 роки тому +2

      @@100jsj6 You probably aren't using a real icon file.

    • @100jsj6
      @100jsj6 3 роки тому

      @@Codemycom Hello sir . Yes that maybe becoz i just renamed file from .png to .ico . I'll try an actual convertor for it . Here is the error thrown in the terminal if that'll help :
      Traceback (most recent call last):
      File "c:\Users\myuser\Desktop\Coding-Items\SPAM\Spam.py", line 13, in
      win.iconbitmap('SPAM_asset.ico')
      File "C:\Users\myuser\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py", line 2080, in wm_iconbitmap
      return self.tk.call('wm', 'iconbitmap', self._w, bitmap)
      _tkinter.TclError: bitmap "SPAM_asset.ico" not defined
      I was adding an icon for a spamming app hence the weird names 😅😅
      Thank you so much for replying sir and that too quickly !

  • @prakulsingla1363
    @prakulsingla1363 3 роки тому +50

    This is the best playlist I can find on python GUI. Amazing.

    • @Codemycom
      @Codemycom  3 роки тому +10

      Thanks! Glad you like it!

    • @Phizzo4real
      @Phizzo4real 2 роки тому

      I have been going thru and learning a ton...

  • @cbaymac
    @cbaymac 4 роки тому +12

    One of the best instructors on UA-cam. Your explanations and format are great. I am going to sign up for your full program. Thanks for all your hard work.

  • @marisko16
    @marisko16 4 роки тому +7

    Man, you are explaining things just the way I would do. Perfect, thank you very much.

    • @Codemycom
      @Codemycom  4 роки тому

      Glad you're enjoying it!

  • @rajofficialjadhav2642
    @rajofficialjadhav2642 Місяць тому +1

    You are one of best coder

  • @myselfsohit
    @myselfsohit 4 роки тому +1

    I have a no words ....frankly speaking i enjoying a lot..thank you so much for your efforts for those can't afford paid courses..love you from INDIA.......

    • @Codemycom
      @Codemycom  4 роки тому +1

      Thanks for watching!

  • @alwayscubing8200
    @alwayscubing8200 3 роки тому +2

    Hey buddy, so awesome...very useful. I have been searching tkinter gui tutorials and fortunately, i found u😃😃

  • @greatindianbuilder2491
    @greatindianbuilder2491 3 роки тому +3

    Thanks for vid, really help. I feel so lucky that I have access to so much information(and tutorials) without any charge.

  • @Zachomara
    @Zachomara 4 роки тому +3

    For new people, PIL is in all caps. Also, you add Pillow from the command line with pip install Pillow. (Stack overflow apparently says its deprecated)
    Also, ImageTk, the "k" is not capitalized. It drove me nuts for about an hour before figuring it out.
    Also thank you for this video. Awesome content.

    • @Codemycom
      @Codemycom  4 роки тому +1

      Was any of that not obvious in the video?

    • @Zachomara
      @Zachomara 4 роки тому

      @@Codemycom I think my main mistakes with it was not hearing the part about the command line. I ended up going to try to install it within the python program at first, and went down a rabbit hole. I'd say user error was the main cause.
      That being said, I learned quite a lot from the videos so far. Like way more than any of the other videos I went through.

    • @Codemycom
      @Codemycom  4 роки тому

      @@Zachomara Cool

    • @farmflight
      @farmflight 4 роки тому

      @@Codemycom ok I keep getting this error code: "No module named 'PIL'" but I added pillow in the command line by using pip install pillow. Do you know what might be happening?

    • @Codemycom
      @Codemycom  4 роки тому

      @@farmflight Did you pip install Pillow (capital P)? You'll have to google it, some people just have problems with it

  • @jorgearmandoperez1450
    @jorgearmandoperez1450 4 роки тому +2

    Man you are my new favorite hero! thanks!

  • @ozbekchawindows4236
    @ozbekchawindows4236 4 роки тому +1

    You are so good... You are my hero! You know everything in Python...

    • @Codemycom
      @Codemycom  4 роки тому +1

      Ha, hardly everything...but thanks!

  • @OsiRixxx
    @OsiRixxx 3 роки тому +1

    if i need to give the code to someone else it will not open the images with my local dirctories, correct? or does python save the .ico internally in the code file? sorry for the dumb question, i am very new to this.

    • @Codemycom
      @Codemycom  3 роки тому

      No it won't, unless you send them the images too.

  • @Hyvexx
    @Hyvexx 4 роки тому +1

    Im using tkinter on a Mac and it seems that for some reason, root.iconbitmap() doesn't work for me. It just changes the icon to a default Mac photo icon. Is there any way you know that allows me to get around this?

    • @Codemycom
      @Codemycom  4 роки тому

      you'll have to google it...there are a bunch of options, and you'll have to try a few to get the one that works for you. stackoverflow is your friend

    • @Hyvexx
      @Hyvexx 4 роки тому

      Codemy.com Oh ok

  • @tablesawart2728
    @tablesawart2728 3 роки тому

    At 4:16 when I click, program crash... The button REMAINS PRESSED and I am forced to stop by clicking on the red x at the top right...
    I'm using Spyder IDE. I repeatedly checked the code, and it turns out absolutely identical. I don't know how to proceed... 😵‍💫

    • @Codemycom
      @Codemycom  3 роки тому

      No, it's not absolutely identical. Check it again, there is an error.

  • @bigstrib
    @bigstrib 2 місяці тому

    I know this is 5 years old it did not quite display what I was looking for.. I do not quite know python and am using AI to help me..I am trying to import font awesome icons...I guess it could be something like "from font_awesome_icons import FontAwesome" it does not seem to work. Do you know of an import that will import icons? I will still look around at other videos..In my code it shows little boxes where the icons should be but it is just not grabbing the icons. I am wondering if importing icons were possible or if I have to save all icons and do it that way.. Thanks.

  • @wingsonlai1132
    @wingsonlai1132 4 роки тому

    5:48 I got an error ---- ModuleNotFoundError: No module named "PIL".
    It seems like I have not installed PIL or/and Pillow.
    Google tells me that I need to install either PIL or Pillow.
    However, google also said that both cannot co-exist.
    How can I know what's the best way to get the image job done for python?
    My laptop/python/pycharm info:
    Windows 10
    Dell Inspiron 5590
    PyCharm 2020.2.1 (Community Edition)
    Python 3.8.3

    • @100jsj6
      @100jsj6 3 роки тому

      go to command prompt and do : pip install pillow

  • @coolgames22ismyname95
    @coolgames22ismyname95 4 роки тому

    Hello, I have a question if you could please help me I would be thankful,
    at 4:26 I have written the code as exactly as I could but it just doesn't work it says. "Python not responding"

    • @Codemycom
      @Codemycom  4 роки тому

      What's the full exact error message?

    • @coolgames22ismyname95
      @coolgames22ismyname95 4 роки тому

      @@Codemycom Thanks for the reply. First of all, this is the code I wrote:
      from tkinter import *
      root = Tk()
      root.title('blah')
      button_quit = Button(root, text="Exit program",command=root.quit)
      button_quit.pack()
      root.mainloop()
      The error message is: "Python is not responding" and it shows me two option that are to report the problem to microsoft or close the program
      Also just a edit i write all this is jupyter

    • @100jsj6
      @100jsj6 3 роки тому

      @@coolgames22ismyname95 that error is of ur pc . its slow maybe... yeah thats definitely it . and if root.quit dont work try command = bleh
      def bleh():
      root.destroy()

  • @victorhuynhvlog
    @victorhuynhvlog Рік тому

    hi sir, at 2:59, when I run the program, it doesnt show the chosen icon on the left top, it just showed the white file icon. i do not know why it happened. Can you help me about it please. Thank you

    • @Codemycom
      @Codemycom  Рік тому

      What did you do differently from the video? Do you have the icon file on your computer in the correct location?

    • @victorhuynhvlog
      @victorhuynhvlog Рік тому

      @@Codemycom I follow step by step from your video. I copied the path of the direction of the photo so I do not think it’s wrong.

    • @Codemycom
      @Codemycom  Рік тому +1

      @@victorhuynhvlogit would work if it wasn't wrong... you have a typo or error of some sort.

    • @victorhuynhvlog
      @victorhuynhvlog Рік тому

      @@Codemycom How to get the icon like yours?

    • @Codemycom
      @Codemycom  Рік тому

      you could download it from my github, or use any icon you want. It's not really important at all. You can leave it off completely if you want@@victorhuynhvlog

  • @muhammadakmalmaulanarizqy7807
    @muhammadakmalmaulanarizqy7807 4 роки тому +1

    hello sir i got a problem this
    Traceback (most recent call last):
    File "C:\Users\USER\AppData\Local\Programs\Python\Python37\imges tkinter.py", line 7, in
    my_img = ImageTk.PhotoImage(Image.open(k))
    NameError: name 'k' is not defined
    how can i do to solve this problem?

    • @Codemycom
      @Codemycom  4 роки тому +1

      There's an error on line 7

  • @marcususa
    @marcususa Місяць тому

    Is there a way to position the images? Like have N, E, W, S (north east west south) where one image is not right next to another or right above?

  • @ndvz8672
    @ndvz8672 3 роки тому

    Whats going on John! LOVE the content. Youre awesome, thank you!

  • @SpinnTV
    @SpinnTV 4 роки тому

    is there a way to use font awsome with python desktop app

  • @pragunashok6008
    @pragunashok6008 4 роки тому +10

    when i try to add an icon, it gives error
    tkinter.Tclerror: bitmap "" is not defined

    • @espanolparatodos7758
      @espanolparatodos7758 4 роки тому

      me toooo
      it's so annoying

    • @himanshushukla787
      @himanshushukla787 3 роки тому +1

      Yeah It's happening with me on linux but on windows it's working

    • @100jsj6
      @100jsj6 3 роки тому

      THAT IS THE EXACT SAME THING HAPPENING WITH ME @Peter Rezkalla i'll try that thanks

  • @ashrsfsiliman452
    @ashrsfsiliman452 4 роки тому +2

    Great job deserving of thanks
    عمل رائع يستحق الشكر

  • @daggercentral9818
    @daggercentral9818 3 роки тому +2

    Traceback (most recent call last):
    File "C:\Users\ACER\images.py", line 2, in
    from PIL import ImageTK,Image
    ImportError: cannot import name 'ImageTK' from 'PIL' (C:\Users\ACER\AppData\Local\Programs\Python\Python39\lib\site-packages\PIL\__init__.py)
    getting this error please help sir...

  • @Franco-rd8du
    @Franco-rd8du 4 роки тому +2

    Hi John, I am having an issue with pillow library, I installed from pip to the last version but every time I try to import the library I get the ModuleNotFoundError: no module named 'PIL'. I'm using visual studio code, but I tried it from Python.exe? (I don't know the name haha) and I get the same error, hope you can help me. Also, I googled this error but it wasn't helpful. Salut

    • @Codemycom
      @Codemycom  4 роки тому

      Google "No module named 'PIL'" and you'll find a bunch of things to try...try em all till one works

    • @Franco-rd8du
      @Franco-rd8du 4 роки тому

      Thanks for answering, I solved it, just had to open cmd and type pipe install pillow and worked

    • @Codemycom
      @Codemycom  4 роки тому

      @@Franco-rd8du Nice!

  • @harshwardhanshirodkar769
    @harshwardhanshirodkar769 4 роки тому +1

    @Codemy.com is there a way we can change the taskbar icon for the file too?

  • @katmanduYT
    @katmanduYT 4 роки тому +1

    I did a program in the past without PIL but I just used img = tk.PhotoImage , can I know the difference between what I used and pil buttons?

  • @TahmidulAzomSany
    @TahmidulAzomSany 3 роки тому +1

    having problem adding icon in LINUX. It's showing
    TclError: bitmap "/home/tasanyphy/Desktop/lens.ico" not defined

    • @Codemycom
      @Codemycom  3 роки тому +1

      You can't use icons on linux, those are windows things

    • @TahmidulAzomSany
      @TahmidulAzomSany 3 роки тому

      Can you please help me out with this things!? I'm already stuck here. And can't move further!

    • @Codemycom
      @Codemycom  3 роки тому +1

      @@TahmidulAzomSany No sorry, I don't have videos on using icons with linux. Remove the icon line in your code, you don't have to add an icon, and move on.

  • @notanamehere8355
    @notanamehere8355 3 роки тому

    I am trying to show the image on a separate window but when I try to set the window for the image to show
    code:
    bgimage = ImageTk.PhotoImage(Image.open("CTNBG.png"))
    bglabel = Label(abctn, image=bgimage)
    bglabel.place(x=0,y=0)
    it gives me an error :
    _tkinter.TclError: image "pyimage1" doesn't exist
    I have 2 windows one named root and one named abctn
    How can I fix this?

    • @Codemycom
      @Codemycom  3 роки тому

      I have videos on the playlist that talk about images on other windows, you need to make them global to avoid tkinter garbage handlers.

    • @notanamehere8355
      @notanamehere8355 3 роки тому

      @@Codemycom oh thanks for replying. I found what the problem was, I needed to make the image's master the second window. I really like your tutorials, great way to start python again after 1 year

  • @diyankalaydzhiev7517
    @diyankalaydzhiev7517 3 роки тому +1

    Hello, i have a question, when i add image and then delete it from the computer it can't run the code. So is there a way to load the image to the code so that is part of it?

    • @ReinierS
      @ReinierS 3 роки тому

      You need to define a place to that image. Everytime you rerun the code it forgets everything in cache. So you can upload the photo on the internet and get it from there. Your code can't memorize your image

  • @keymediastudioitself
    @keymediastudioitself 4 роки тому +14

    To avoid resizing put:
    # app = your root
    app.resizable(width=False, height=False)

    • @tomabrasoveanu
      @tomabrasoveanu 3 роки тому

      how do i tell what my root is?

    • @100jsj6
      @100jsj6 3 роки тому +1

      @@tomabrasoveanu the name "app" is a variable which contains tk.Tk() so this is what the code wud be:
      from tkinter import *
      # * signifies all
      #create a variable to host the app with the name of ur choice . im doing "hi" over here
      hi = Tk()
      #it will be tk.Tk() if u do "import tkinter " instead of "from tkinter import *"
      hi.resizable(width= False , height= False)
      hi.mainloop()
      #now ,the app wont be resizable

    • @100jsj6
      @100jsj6 3 роки тому

      i hope i satisfied your question by giving an answer 😃😃

    • @Viicorico
      @Viicorico 2 роки тому

      @@100jsj6 hi what do u mean by resizable ?

    • @100jsj6
      @100jsj6 2 роки тому

      @@Viicorico i mean that the window isnt resizable

  • @michaelvidanes6629
    @michaelvidanes6629 2 роки тому

    Can you help me find a solution on retaining images in Tkinter? That's because the image just pops-up when loaded, the it disappers. Hope you can help me. Thanks.

  • @Harish-ou4dy
    @Harish-ou4dy 5 років тому +8

    I converted my .jpg image into an .ico image using an online converter tool and used in my program. The icon in my window doesn't appear, but it shows a blank image.

    • @Codemycom
      @Codemycom  5 років тому +4

      maybe the converter tool sucks...

    • @infinitespace1982
      @infinitespace1982 4 роки тому

      @@Codemycom Then what do you suggest?

    • @infinitespace1982
      @infinitespace1982 4 роки тому +1

      What you're probably doing wrong is that you are not specifying the NAME of the ico file after the directory, e.g.
      'c:/gui' is the directory and 'codemy.ico' is the name of the ICO file, thus you must typer the following:
      (r'c:/gui/codemy.ico') in full (DON'T FORGET THAT 'r')

    • @Codemycom
      @Codemycom  4 роки тому +1

      @@infinitespace1982 Using a different tool...or making your own in photoshop or the free gimp or any other graphics tool that will let you make and icon.

    • @anushkamble85
      @anushkamble85 4 роки тому

      @@infinitespace1982 Not admitting that he has maybe make a mistake

  • @DrizztStrife
    @DrizztStrife 3 роки тому

    For the icon
    root.iconbitmap(r'c:\_Python\Icons\icon.ico')
    I successfully remove the default feather icon, but it is replaced with a blank page icon. I've tried .ico images 512x512 and 256x256- what am I doing wrong?

    • @Codemycom
      @Codemycom  3 роки тому

      I don't know, but that code doesn't look anything at all like mine. Maybe start there.

  • @nihalthannegedarapremaratn2352
    @nihalthannegedarapremaratn2352 4 роки тому +1

    Very helpful. Thanks you..... Hope continue.....

    • @Codemycom
      @Codemycom  4 роки тому

      Glad you liked it...there's like 50 more videos in this playlist

  • @ritajbhosale6816
    @ritajbhosale6816 5 років тому +1

    is there any way to make the picture\photo to be in circle\oval .. or how can i make the corners transparent of the image.. i can use any image just i want the picture to seen in circular format..

    • @oneilmw
      @oneilmw 5 років тому +1

      Image formats generally have four channels: a red channel, a green channel, a blue channel, and an alpha channel.
      The alpha channel is the "transparency" layer, and works just like the other three: each pixel has its own red, green, blue, and alpha value.
      If you turn the alpha value of the corner pixels to 0, you can get rounded corners.
      If you're looking for a way to automate this vignette within tkinter, good luck to you; it's probably a lot of work.
      Alternatively, you could (theoretically) make a corner image in your background color, anchor it to it's corresponding corner, then draw that on top of your image to trick the user into thinking that the image has rounded corners. I haven't tested it, but it is something to try.

  • @amankumarbairagi794
    @amankumarbairagi794 4 роки тому +2

    Sir, Which type of editor do you use for programming in python ?

    • @Codemycom
      @Codemycom  4 роки тому +1

      I use the sublime text editor and the git bash terminal

  • @funnyanimalworld7579
    @funnyanimalworld7579 4 роки тому +1

    how to resize image button on a grid when you resize window of a program.i know how to resize a button but not a text or image on a button ,those stay the same

  • @marcmathieutrance6807
    @marcmathieutrance6807 2 роки тому

    I have encounter an error during the iconbitmap tutorial. the error says: unicodeescape: codec can't decode bytes in position 2-3. I google it and it direct me to stack overflow where I found the solution. prefix the string with (to produce a raw string):

    • @Codemycom
      @Codemycom  2 роки тому +1

      Glad you got it sorted out

  • @elchinefa9524
    @elchinefa9524 4 роки тому

    Hi. Is the an option to run python program with double click? something like .exe file. Or i must create .bat file? Thanks in advance.

    • @Codemycom
      @Codemycom  4 роки тому +1

      Yes, you can make them into exe files. Check the playlist, I have a video on that

    • @elchinefa9524
      @elchinefa9524 4 роки тому

      @@Codemycom Thanks a lot, i'll check it tomorrow.

  • @Eulers_identity132
    @Eulers_identity132 10 місяців тому

    Great Tutorial! I'm watching this 5 years later, but there's a function called Eval() in python. You could use this to make it a scientific calculator and make the evaluation function just evaluate the string.

  • @TakeMorePics
    @TakeMorePics 4 роки тому +1

    Im following the instructions perfectly, but cant seem to get the icon part to work. I am on Ubuntu 18. The icon I have is called Chrome.ico and is in the same directory as the program that is calling it. I even tried the entire path to the .ico file, and that doesnt work either.
    from tkinter import *
    root = Tk()
    root.title('Learn To Code at Codemy.com')
    root.iconbitmap('Chrome.ico')
    root.mainloop()
    and I get the error:
    tkinter.TclError: bitmap "Chrome.ico" not defined

    • @Codemycom
      @Codemycom  4 роки тому +2

      Icon files don't work on ubuntu.. you need an xbm file and must append it with a @ sign (I think)
      root.iconbitmap('@/home/whatever/Chrome.xbm') or something like that...

    • @TakeMorePics
      @TakeMorePics 4 роки тому

      @@Codemycom how do you know all this stuff? Thanks!

    • @Codemycom
      @Codemycom  4 роки тому +3

      @@TakeMorePics lol no idea, haha

  • @kiem2702
    @kiem2702 3 роки тому

    "SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape"
    I'm using VSCode and I get this error when I use the full path of both the icon and the image both in and not in the same folder of the python file. But when I put it in the same folder of the python file and only put the relative path, it works. How do I fix this?

  • @m99-f7i
    @m99-f7i 4 роки тому +2

    Hi, I got an error: "TclError: bitmap "iconoprueba.icon" not defined", the icon is in the same folder where the file ".py" is. What can I do?. I hope you can help me with that.

    • @Codemycom
      @Codemycom  4 роки тому +1

      it should be iconoprueba.ico not iconoprueba.icon, that's why you got an error.

    • @atomic-blade6977
      @atomic-blade6977 3 роки тому

      @@Codemycom i still get it any solutions

  • @maxwellhawk
    @maxwellhawk 2 роки тому

    ok. I have issue with this particular tutorial. First of all i get an error from iconbitmap line: bitmap "icon.ico" not defined. Icon in the folder, it is in ico format. Other issue with Pillow. I installed pillow 9.3.0 i believe, when I used import from PIL it say no PIL module. I successfully been able to add icon by using:
    from tkinter iport *
    from tkinter.ttk import *
    method iconphoto with PhotoImage parameter.
    Is this instructions outdated and no longer applies or I am doing something wrong?

    • @Codemycom
      @Codemycom  2 роки тому

      Nothing has changed, you're doing something wrong.

    • @maxwellhawk
      @maxwellhawk 2 роки тому

      @@Codemycom so what could be a problem? I work on linux. I have installed pillow, yet when i run code on pycharm it say No module named PIL

    • @maxwellhawk
      @maxwellhawk 2 роки тому

      ok. so on linux it should be xbm file not ico, also in address if file in same folder must be @ at the beginning. Yet i still dont get icon on the window even though window is pop up.

    • @Codemycom
      @Codemycom  2 роки тому

      @@maxwellhawk No clue, Pycharm sucks...I don't use or recommend it.

    • @maxwellhawk
      @maxwellhawk 2 роки тому

      @@Codemycom well it's not like i have a much of a choise. I was trying to get idle but couldn't make it work on linux, i also uncomfortable to use terminal. It kinda weird that it execute string by string, feels wrong, so I googled it and pycharm is most recommended of all. Some of codes of yours btw didn't work on terminal but only in pycharm.

  • @viswamberprasad9418
    @viswamberprasad9418 4 роки тому +1

    I used the exact same lines as yours.
    i stored the icon as ".ico" in the same location(desktop) as my ".py" file,but when i run the code,it raises this error
    _tkinter.TclError: bitmap "C:/Users/Dell/Desktop/icon.ico" not defined.
    would really appreciate it if anyone can help me out!

    • @Codemycom
      @Codemycom  4 роки тому +1

      Is the file a real ico file?

    • @thehappyopossum
      @thehappyopossum 4 роки тому +1

      i am having the same issue also, if anyone knows a fix or suggestion to fix this, would be greatly appreciated

    • @viswamberprasad9418
      @viswamberprasad9418 4 роки тому +1

      @@thehappyopossum hey bud,just make sure that it is a real .ico file and also that it is in a separate folder with your python file

  • @yashar696
    @yashar696 4 роки тому +1

    Thanks it was great & very useful♥♥

  • @emanuelshemesh
    @emanuelshemesh 4 роки тому +1

    whn i try to run the pogram it says photoimage' object has no attribute '_photoimage__photo' any ideas what i should do??

  • @focusfail.
    @focusfail. 4 роки тому +3

    Hello, I have got a problem. I am getting an error wich sais "No module named" PIL" I have already reinstalled Pillow multiple times.

    • @harshwardhanshirodkar769
      @harshwardhanshirodkar769 4 роки тому

      I got a similar error , while I was able to download pillow library using pip I kept getting an error, I finally found a solution on stack overflow that just required me to update path variables.
      stackoverflow.com/questions/44515769/conda-is-not-recognized-as-internal-or-external-command
      in case anyone wants to refer to it

    • @afonsofraguas1145
      @afonsofraguas1145 4 роки тому

      try this before "python -m pip install --upgrade pip"

  • @fayizhalim3145
    @fayizhalim3145 4 роки тому

    Hei Bro can i ask you a question. I still confused how to make my image appear even though i follow the step by step it won't work. Text like this appear in the Terminal "No such file or directory E:\ (My location file)".
    I don't know why it won't appear.

    • @fayizhalim3145
      @fayizhalim3145 4 роки тому

      And fyi i've already installed Pillow Function

  • @yogeshwarns3821
    @yogeshwarns3821 2 роки тому

    Sir.what is the compiler u are using??

  • @nirmalkumarpattanaik1942
    @nirmalkumarpattanaik1942 4 роки тому

    I reinstalled Python and checked add to path over there and I was able to install pillow. But when I try to insert images, it says:
    No Module named PIL
    Please help.
    This is my code:
    from tkinter import *
    from PIL import ImageTk,Image
    root=Tk()
    my_img=ImageTk.PhotoImage(Image.open('cop.png'))
    my_label=Label(image=my_img)
    my_label.pack()
    root.mainloop()

    • @Codemycom
      @Codemycom  4 роки тому

      Some people just have trouble with PIL, you'll have to google that error - there could be a dozen solutions.

    • @nirmalkumarpattanaik1942
      @nirmalkumarpattanaik1942 4 роки тому

      @@Codemycom I tried a lot but couldn't fix it 😥😭

    • @nirmalkumarpattanaik1942
      @nirmalkumarpattanaik1942 4 роки тому

      @@Codemycom I tried it in PyChram and it works! Dunno why it doesn't work in Sublime text

  • @FRIENDSofCAP
    @FRIENDSofCAP 5 років тому

    Hi, Tim here. Question... I am running a Mac Pro desktop computer running Mac oSX(Mojave) and using Visual Studio Code as my IDE with Python 3.7.4... I have tried adding 'mainWindow.iconbitmap('filename.ico) which includes any path prefixes but don't see any icon at all. Any ideas as to why this is? Any tips on addressing this issue? Any help is greatly appreciated. Thanks

    • @Codemycom
      @Codemycom  5 років тому

      Check this out for your answer... stackoverflow.com/questions/33134594/set-tkinter-python-application-icon-in-mac-os-x

  • @TahmidulAzomSany
    @TahmidulAzomSany 3 роки тому +19

    Those who are getting delayed by the exit button: You can use root.destroy instead of root.quit

  • @harryman3347
    @harryman3347 4 роки тому +1

    I done the same as 2:45
    But it says can't deode bytes untruncated

    • @Codemycom
      @Codemycom  4 роки тому

      Check your code for typos

  • @mikhailkevin2505
    @mikhailkevin2505 2 роки тому

    good afternoon sir, i want to ask something about tkinter, can we display terminal python with it?

  • @selinsabrcan2848
    @selinsabrcan2848 3 роки тому

    Hello, I am having difficulty visualizing my png images. I currently have them in a file on my desktop called project_file. I am using "c:/desktop/project_file/imagename" but python is giving me an error. Can someone tell me what I'm doing wrong? Or how to fix this issue! Thanks

  • @raniduharshana5238
    @raniduharshana5238 4 роки тому +6

    Thank you very much. I learnt a lot about tkinter. 🤭❤️

    • @Codemycom
      @Codemycom  4 роки тому +2

      Glad it was helpful!

  • @aadityasahoo6244
    @aadityasahoo6244 3 роки тому

    hey john, kudos on making an amzing playlist!
    coming to my question: im getting an error while doing this
    ```img = ImageTk.PhotoImage(Image.open(path))
    AttributeError: type object 'Image' has no attribute 'open'```
    so im chosing path from the askopenfilename method, and then applyiong it here but for some reason it doesnt work. any suggestions?
    Thanks.

    • @Codemycom
      @Codemycom  3 роки тому +1

      did you pip install Pillow and import Image at the top of your file?

    • @aadityasahoo6244
      @aadityasahoo6244 3 роки тому

      @@Codemycom thanks so much for replying!
      anyway, yes i did install pillow and import the image, and did everything u did, but for the life of me i cant figute out what it is that ive done wrong!

    • @Codemycom
      @Codemycom  3 роки тому

      @@aadityasahoo6244 Set it aside for a couple days and look at it with fresh eyes...you probably just misspelled something

  • @ehsam8202
    @ehsam8202 2 роки тому

    i can’t seem to figure out how to add 2 images onto the screen. when i use myLabel.grid(row=0, column=0) and different rows and columns for the second image it doesn’t work

    • @Codemycom
      @Codemycom  2 роки тому

      Check your code for errors. If you can add 1 image, you can add 2 the same way. The second image has to be named something other than myLabel.....name it myLabel2 or something.

  • @vic-san12
    @vic-san12 3 роки тому

    I love your videos. I learned a lot from them. More power to you!

  • @mrawesome7739
    @mrawesome7739 3 роки тому

    I have Pillow installed, but this happens:
    Traceback (most recent call last):
    File "/home/pi/Coding/Python_coding/First_100_Codes/Tkinter_icons_images_and_exits.py", line 2, in
    from PIL import ImageTk,Image
    ImportError: cannot import name 'ImageTk' from 'PIL' (/usr/lib/python3/dist-packages/PIL/__init__.py)

    • @Codemycom
      @Codemycom  3 роки тому

      try installing it again

  • @God_OfGame
    @God_OfGame 3 місяці тому

    very very nice❣❣❣

  • @sirvex7514
    @sirvex7514 11 місяців тому

    im gonna be honest mr heisenberg you look extremely cute with the doggo

  • @Spacekriek
    @Spacekriek Рік тому

    Great series, thank you very much. What I do find irritating about these software packages, IDEs etc is this trend to add plugins and packages afterwards. Never complete. It's like buying a car and discovering you still need a spare wheel, side view mirrors... Oh, do you need an engine too, sir ? No problem, just download it ! :)

    • @Codemycom
      @Codemycom  Рік тому +1

      But when adding something happens in 10 seconds, for free...why does that bother you?

    • @Spacekriek
      @Spacekriek Рік тому

      @@Codemycom Just a work in progress, then. :)

  • @fsldr
    @fsldr 8 місяців тому +1

    thanks a lot man!

  • @ritusree05
    @ritusree05 4 роки тому

    Sir I use python idle for my tkinter projects. I used the same as you to add exit button to the tkinter window, but the code didn't work . It just brought up a button with the text and no function at all. I was sure I provided the quit function to it with the exact code as you. Can I get a help from you?

    • @Codemycom
      @Codemycom  4 роки тому

      Don't use idle

    • @ritusree05
      @ritusree05 4 роки тому

      @@Codemycom Does idle not support certain function? Or is not there some other way to perform the exit button function?

    • @Codemycom
      @Codemycom  4 роки тому

      @@ritusree05 It's idle...why would you use it?

    • @ritusree05
      @ritusree05 4 роки тому

      @@Codemycom OK then.... I will try not to use it any more. Thank you sir.

    • @100jsj6
      @100jsj6 3 роки тому

      @@ritusree05 sir u can try using root.destroy in built function instead

  • @sp8871
    @sp8871 3 роки тому

    Hello. I get AttributeError: 'PhotoImage' object has no attribute '_PhotoImage__photo'. Do you know what could be the problem?

    • @Codemycom
      @Codemycom  3 роки тому

      looks like you have an error in your code.

  • @EGGFRENZY2015
    @EGGFRENZY2015 4 роки тому

    how would you set the image in the top right? so it is always in the top right?

    • @Codemycom
      @Codemycom  4 роки тому

      maybe check the video I have on status bars..it shows how to put stuff in the bottom right, and you can modify that

  • @AshikurRahman-ny9ul
    @AshikurRahman-ny9ul 4 роки тому

    Is quit a built-in method for pyCharm IDE?

    • @Codemycom
      @Codemycom  4 роки тому

      The IDE you use is irrelvant...we aren't writing code for an IDE...we're just writing Python code

  • @namanchhibbbar2205
    @namanchhibbbar2205 4 роки тому +1

    you are really awesome, highly appreciate your work

    • @Codemycom
      @Codemycom  4 роки тому

      Thank you! I appreciate that!

  • @Dnxkdex
    @Dnxkdex 4 роки тому

    I’m using a chromebook to do my coding in, however i can’t find the location/ direct path of my ico file, is there any videos you can direct me to that will help resolve this problem

    • @Codemycom
      @Codemycom  4 роки тому

      Yeah, I don't know how you can use a chromebook with tkinter

  • @sarthakbhutani7413
    @sarthakbhutani7413 4 роки тому

    sir this is not working in py3
    return self.tk.call('wm', 'iconbitmap', self._w, bitmap)
    _tkinter.TclError: bitmap "C:/Users/Mausam/Desktop/instagram.ico" not defined

    • @Codemycom
      @Codemycom  4 роки тому

      try lowercase c in c:/

    • @333-n4q
      @333-n4q 4 роки тому

      that doesn't work either. Getting the same error.

    • @Codemycom
      @Codemycom  4 роки тому

      @@333-n4q check your code for typos

  • @douglasmonteiro3085
    @douglasmonteiro3085 5 років тому +1

    Hi,
    I am getting the error : No module named 'PIL'. I have installed Pillow. and trying the other tips from stackoverflow/google. Do you have any Idea of what it can be?

    • @Codemycom
      @Codemycom  5 років тому

      It could be a bunch of different things. Google "No module named 'PIL'" and you'll find a bunch of things to try...try em all till one works :-p

    • @douglasmonteiro3085
      @douglasmonteiro3085 5 років тому

      @@Codemycom Hi Jhon I have spent the last week going over and over this error and I cannot figure it out haha, I have uninstalled and installed python again following the right procedure. unfortunately it still doesn't work. But I am stubborn haha. one question, when u do pip freeze you get a bunch of things installed, do they have any relation with this program? Also, if I have Image and Pillow installed can it be a problem ? I have tried them together, one or another by itself, but still nothing haha.

    • @douglasmonteiro3085
      @douglasmonteiro3085 5 років тому +1

      @@Codemycom After a long week trying different things, what has finally worked for me was...changing the editor. I was using pycharm and nothing worked out. with Atom things finally worked.
      finally I can keep going with the tutorial hahaha

    • @Codemycom
      @Codemycom  5 років тому

      @@douglasmonteiro3085 Awesome! Yeah I don't like pyCharm personally. I stick with Sublime Text and I never have a problem.

  • @elysonpanolino7522
    @elysonpanolino7522 2 роки тому +1

    How can I resize the image?

    • @Codemycom
      @Codemycom  2 роки тому

      Check the playlist, I have videos on that.

  • @mariannagladysz5191
    @mariannagladysz5191 4 роки тому

    Is it possible that command=root.quit doesn't work on Mac?

    • @Codemycom
      @Codemycom  4 роки тому

      it doesn't work in IDLE...but you shouldn't be using IDLE anyway

  • @charleymai5270
    @charleymai5270 4 роки тому

    I keep getting this problem when I try to change the icon image.
    So whenever I run
    from tkinter import *
    root = Tk()
    root.title("Images")
    root.iconbitmap('C:/photos/red.ico')
    root.mainloop()
    This error would pop up
    File "C:\Users\charl\AppData\Local\Programs\Python\Python38-32\lib\tkinter\__init__.py", line 2071, in wm_iconbitmap
    return self.tk.call('wm', 'iconbitmap', self._w, bitmap)
    _tkinter.TclError: bitmap "c:/photos/red.ico" not defined
    I have the icon in a folder that is inside of the python folder but it keeps giving me this error.
    Is there any way that I can make this work?

    • @Codemycom
      @Codemycom  4 роки тому

      use lowercase C
      root.iconbitmap('c:/photos/red.ico')

  • @pranavdabre1816
    @pranavdabre1816 4 роки тому

    Hey there.
    I confronted an issue; My code is running well but the tkinter window is showing just a small part of my image though the window is in full size(i.e. fully covering my display).
    Running spyder=4.1.2 And Pillow=6.1.0
    image is jpg and size is 4.54MB
    please guide 😊

    • @Codemycom
      @Codemycom  4 роки тому

      Sorry, I don't know Spyder but it gives a lot of people trouble. Why not use the free tools I use?

    • @pranavdabre1816
      @pranavdabre1816 4 роки тому

      @@Codemycomi used spyder just as an editor, It has nothing to do with it I guess
      Still, I ran the same py file in cmd giving me the same results, part of the image is still cut and part is visible.
      Perhaps it has something to do with its size!☹

    • @Codemycom
      @Codemycom  4 роки тому

      @@pranavdabre1816 could be

    • @pranavdabre1816
      @pranavdabre1816 4 роки тому

      @@Codemycom Sorry to bother you
      You've just created a video on my issue 2 weeks ago!!😅😅

  • @onio1
    @onio1 2 роки тому

    Any way to fit an image to the size of a button? Or do the image needs to previously be the size of such button?! Great videos by the way! KUDOS!!!

  • @aravind.m6266
    @aravind.m6266 Рік тому

    am using grid system, if i click the exit button the gui is not automatically closing can u hel me?

    • @Codemycom
      @Codemycom  Рік тому +1

      Has nothing to do with the grid system. You likely have a typo or did something different from the video. Try root.quit()

    • @aravind.m6266
      @aravind.m6266 Рік тому

      @@Codemycom thank u, but its working but its asking do you want to kill the program and when i click yes then only its closing

    • @aravind.m6266
      @aravind.m6266 Рік тому

      its working on visual studio code but not in python idle but thank u so much

  • @sahilsaha4012
    @sahilsaha4012 4 роки тому

    Hello sir as you wrote the Image.open( " image1.png").. this portion is not working in my system..

    • @Codemycom
      @Codemycom  4 роки тому

      No space after the " in "image1.png"

  • @Jumbjetsky
    @Jumbjetsky 2 роки тому

    I have a hard time putting all this together to obtain what i need.
    I want the following:
    1. click on icon open a window.
    2. Window contains button or drop down, for "open file" to browse for a file containing txt/csv data
    3. when file is opened, the pathway is obtained
    4. A button with a built in function runs an analysis on the data. And visualizations are displayed for quality control check.
    5. Button to submit data to a database
    I want all of the above to be on 1 window, even when data is displayed. But i cannot figure out whether tkinter can do that. I have only figured out to do this in a series of events composed of several windows which are opened, then closed for the next window to appear.
    Hope you can help

    • @Codemycom
      @Codemycom  2 роки тому

      Yeah, there's nothing to all of that. I have videos on pretty much all of that in this playlist.

  • @kidredglow2060
    @kidredglow2060 Рік тому

    i installed pillow, but in python, it underlines PIL in red, and also ImageTk, and Image

  • @evenvonschemde8746
    @evenvonschemde8746 4 роки тому +3

    After i have installed Pillow it still says "No module named 'PIL'" when i try running the program. Someone help?

    • @safalkumarsinha5110
      @safalkumarsinha5110 4 роки тому +1

      Have you installed PILLOW?

    • @adityasagar9078
      @adityasagar9078 4 роки тому

      same problem ,I installed pillow but it says no module PIL available

    • @bahnus6312
      @bahnus6312 3 роки тому

      If you use “studio visual code” i Can help you guys

  • @mdzohaib7368
    @mdzohaib7368 4 роки тому

    Sir the root.quit function is not working in my pc nd also i m not getting any error.
    Whenever i press exit button nothing happens. It just stays as it is.
    No error also.

    • @Codemycom
      @Codemycom  4 роки тому

      Did you forget to put () on quit?

    • @mdzohaib7368
      @mdzohaib7368 4 роки тому

      Actually i tried both root.quit() nd i also tried root.quit both arent working.
      I think its working by root.quit bt its not showing getting exit.
      Its may be my python shell editor mode problem.
      I ll try it on framework

    • @Codemycom
      @Codemycom  4 роки тому +1

      @@mdzohaib7368 Oh yeah, tkinter doesn't work in a python shell. Use the tools I do, sublime text and the git bash terminal.

    • @nirmalkumarpattanaik1942
      @nirmalkumarpattanaik1942 4 роки тому

      I was facing the same problem too. But then, I used 'command=quit' and it worked for me

  • @vik0_052
    @vik0_052 4 роки тому

    is there a way to make a back/reverse button in tkinter?

    • @Codemycom
      @Codemycom  4 роки тому

      Sure...it just depends what you want to go back on

    • @vik0_052
      @vik0_052 4 роки тому

      @@Codemycom Sir did you make a video for it, I have been searching through your series but I couldn't find any?

  • @bheriraju722
    @bheriraju722 3 роки тому

    I tried this way
    my_img=Label(image=ImageTk.PhotoImage(Image.open("a.ico"))).pack()
    There is no error but image did not display
    If i split then image is displayed
    my_img=ImageTk.PhotoImage(Image.open("a.ico"))
    my_img1=Label(image=my_img).pack()
    can you tell me why?

    • @Codemycom
      @Codemycom  3 роки тому

      You never want to put it all on one line...as you've discovered

  • @ehsam8202
    @ehsam8202 2 роки тому

    if i wanted to randomly select 1 image from a bunch of images how would i go upon doing that

    • @Codemycom
      @Codemycom  2 роки тому +1

      Add them all to a list and randomly select an item from the list in the normal way: random.choice(yourlist)

  • @vik0_052
    @vik0_052 4 роки тому

    how can I print the output only once if I click a button widget?

    • @Codemycom
      @Codemycom  4 роки тому +1

      Run an if statement in the function to see if the output has been printed already

  • @kindersmith8407
    @kindersmith8407 4 роки тому

    from tkinter import *
    root = Tk()
    root.title('bruh')
    root.iconbitmap('c:/gui/yeet.ico')
    root.mainloop()
    it just has a unreadable file as the picture, its an ico though. What do I do? Its just some blank piece of paper that I can't figure out how to get rid of!

    • @Codemycom
      @Codemycom  4 роки тому

      That's a blank app...what did you think would happen? remove the root.iconbitmap line

  • @Manish_Kumar_04
    @Manish_Kumar_04 4 роки тому

    Hi John, my side its showing unicode error, can't decode... whatever it is, also I'm not able to use pillow as you've told, what I'll do now?

  • @Rshers
    @Rshers 2 роки тому

    This is ridiculous but is it important to put the root (root, text=" ") is there any effects if i delete it?

    • @Codemycom
      @Codemycom  2 роки тому

      you need to put the root always.

  • @rocketleagueshorts1961
    @rocketleagueshorts1961 4 роки тому

    when i run this i get the error which says Image doesnt have an attribute open so i did 'print(dir(Image))' and i found that there is not really a attribute for Image named open. what can i do sir plz plz plz give me a solution.
    I USE UBUNTU 18.04
    PYTHON 3.6

    • @Codemycom
      @Codemycom  4 роки тому

      You have a typo or something. What did you do differently than my code?

    • @rocketleagueshorts1961
      @rocketleagueshorts1961 4 роки тому

      @@Codemycom
      ​from tkinter import *
      from PIL import ImageTk,Image
      root=Tk()
      img=ImageTk.Pictureimage(Image.open('answer1.png'))
      lab=Label(Image=img)
      lab.pack()
      root.mainloop()
      AND THE ERROR IS
      Traceback (most recent call last):
      File "image.py", line 5, in
      img=ImageTk.Pictureimage(Image.open('answer1.png'))
      AttributeError: module 'PIL.ImageTk' has no attribute 'Pictureimage'

    • @Codemycom
      @Codemycom  4 роки тому +1

      @@rocketleagueshorts1961 Yep, exactly as I said. It's not Pictureimage, it's PhotoImage

    • @rocketleagueshorts1961
      @rocketleagueshorts1961 4 роки тому

      @@Codemycom thanx a lot sir actually i tried PhotoImage and then Pictureimage and just now i noticed the 'i' in PhotoImage should be capital. Thanks for your time and help

  • @borgyoh
    @borgyoh 5 років тому +1

    at around 4:19 when you tested the quit button, i copied exactly what you types minus the image of course and my button shows up but it wont click. im using a mac btw.

    • @Codemycom
      @Codemycom  5 років тому +1

      you might have a typo that you aren't noticing. Let me see your code..

    • @borgyoh
      @borgyoh 5 років тому +1

      @@Codemycom not sure how i can show you without a screen shot. i copied your verbatim exactly. the button shows up but when i click , it doesnt do anything. i also had a problem with getting the image to show up in the window. ithe error is a "file not found" as in the location of the image file. i assume things are different on a mac. i copy the exact file address of the image and still get an error.

    • @Codemycom
      @Codemycom  5 років тому +2

      ​@@borgyoh you could copy and paste the code here

    • @borgyoh
      @borgyoh 5 років тому +1

      @@Codemycom from tkinter import *
      from PIL import ImageTk , Image
      root = Tk()
      root.title("buttons and images")
      #skipped icon on header
      button_quit = Button(root, text= "exit program" , command = root.quit)
      button_quit.pack()
      root.mainloop()

    • @Codemycom
      @Codemycom  5 років тому +6

      @@borgyoh in your button command, try comand = root.destroy. If that doesn't work, try
      import sys
      #at the top of your program
      button_quit = Button(root, text= "exit program" , command=sys.exit)
      if that doesn't work, still import sys, but create a function called quit
      import sys
      #at the top of your program
      def quit():
      sys.exit()
      and call command=quit from your button

  • @talefraim8118
    @talefraim8118 2 роки тому

    Thank you so much. I can see the icon while running my code on windows. but, when i'm trying to run it on Linux, the main window is appearing without the icon, what can be the reason to that?

    • @Codemycom
      @Codemycom  2 роки тому +1

      Windows icon files don't work on linux. You have to google linux icons for the solution

  • @Capsaicinophile
    @Capsaicinophile 2 роки тому +5

    Walter White teaches Tkinter like a boss.

  • @johnnyjay
    @johnnyjay 4 роки тому +1

    I'm getting an error
    File "/Users/.../mu_code/gui tutorials/imagescode.py", line 9
    my_label = Label(image=my_img)
    ^
    SyntaxError: invalid syntax

    • @gloryags8906
      @gloryags8906 4 роки тому +2

      l should be big L

    • @jyotipandita8552
      @jyotipandita8552 4 роки тому

      You need to use a PhotoImage() class to do that:
      Image = PhotoImage(file="Image.png")
      Label(image = Image).pack()

  • @TechWithSabri
    @TechWithSabri 5 років тому

    Hello sir
    can you tell me please what's the difference between
    btn_quit = Button(root,text='Exit',command = root.quit) and this
    btn_quit = Button(root,text='Exit',command = root.quit() )
    when we call the method " quit " without parentheses it's working but when we call it with parentheses doesn't work why ?
    by the way thank you so much

    • @Codemycom
      @Codemycom  5 років тому +1

      in tkinter you don't use () to call functions.

  • @tommajor4587
    @tommajor4587 5 років тому +1

    When running the root.iconbitmap(file path) I get a TclError: bitmap not defined. Is the image faulty or is my code wrong?

    • @Codemycom
      @Codemycom  5 років тому

      Open the image in some other program to see if it's faulty. Then google "TclError: bitmap not defined." and you'll find a solution...

    • @tommajor4587
      @tommajor4587 5 років тому

      @@Codemycom I have tried this, there's one decent article on stackoverflow and I tried everything and still doesn't work.

    • @Codemycom
      @Codemycom  5 років тому

      @@tommajor4587 then maybe it is your image

    • @tommajor4587
      @tommajor4587 5 років тому

      @@Codemycom I have saved as .ico as a bitmap and a JPEG and even download GIMP to test, image is fine.

    • @Codemycom
      @Codemycom  5 років тому

      @@tommajor4587 try downloading an actual icon from the web and trying that.