▶️ 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
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()
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
@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 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 !
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.
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.......
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 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 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?
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.
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?
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... 😵💫
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.
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
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 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
@@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()
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
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
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?
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...
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
@@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.
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 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
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?
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
@@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
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.
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.
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')
@@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.
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?
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..
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.
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
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):
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.
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
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...
"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?
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.
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?
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 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.
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!
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
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.
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()
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
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
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 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!
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
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.
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)
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 ! :)
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?
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
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
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 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.
@@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
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?
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 😊
@@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!☹
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
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.
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
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?
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!
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 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 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
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 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.
@@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
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?
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
▶️ 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
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()
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
@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
@@100jsj6 You probably aren't using a real icon file.
@@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 !
This is the best playlist I can find on python GUI. Amazing.
Thanks! Glad you like it!
I have been going thru and learning a ton...
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.
Man, you are explaining things just the way I would do. Perfect, thank you very much.
Glad you're enjoying it!
You are one of best coder
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.......
Thanks for watching!
Hey buddy, so awesome...very useful. I have been searching tkinter gui tutorials and fortunately, i found u😃😃
Glad you did
Thanks for vid, really help. I feel so lucky that I have access to so much information(and tutorials) without any charge.
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.
Was any of that not obvious in the video?
@@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.
@@Zachomara Cool
@@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?
@@farmflight Did you pip install Pillow (capital P)? You'll have to google it, some people just have problems with it
Man you are my new favorite hero! thanks!
Wow, thanks!
You are so good... You are my hero! You know everything in Python...
Ha, hardly everything...but thanks!
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.
No it won't, unless you send them the images too.
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?
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
Codemy.com Oh ok
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... 😵💫
No, it's not absolutely identical. Check it again, there is an error.
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.
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
go to command prompt and do : pip install pillow
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"
What's the full exact error message?
@@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
@@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()
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
What did you do differently from the video? Do you have the icon file on your computer in the correct location?
@@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.
@@victorhuynhvlogit would work if it wasn't wrong... you have a typo or error of some sort.
@@Codemycom How to get the icon like yours?
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
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?
There's an error on line 7
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?
Whats going on John! LOVE the content. Youre awesome, thank you!
thanks!
is there a way to use font awsome with python desktop app
No clue, sorry
when i try to add an icon, it gives error
tkinter.Tclerror: bitmap "" is not defined
me toooo
it's so annoying
Yeah It's happening with me on linux but on windows it's working
THAT IS THE EXACT SAME THING HAPPENING WITH ME @Peter Rezkalla i'll try that thanks
Great job deserving of thanks
عمل رائع يستحق الشكر
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...
Ditto
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
Google "No module named 'PIL'" and you'll find a bunch of things to try...try em all till one works
Thanks for answering, I solved it, just had to open cmd and type pipe install pillow and worked
@@Franco-rd8du Nice!
@Codemy.com is there a way we can change the taskbar icon for the file too?
no
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?
having problem adding icon in LINUX. It's showing
TclError: bitmap "/home/tasanyphy/Desktop/lens.ico" not defined
You can't use icons on linux, those are windows things
Can you please help me out with this things!? I'm already stuck here. And can't move further!
@@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.
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?
I have videos on the playlist that talk about images on other windows, you need to make them global to avoid tkinter garbage handlers.
@@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
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?
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
To avoid resizing put:
# app = your root
app.resizable(width=False, height=False)
how do i tell what my root is?
@@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
i hope i satisfied your question by giving an answer 😃😃
@@100jsj6 hi what do u mean by resizable ?
@@Viicorico i mean that the window isnt resizable
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.
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.
maybe the converter tool sucks...
@@Codemycom Then what do you suggest?
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')
@@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.
@@infinitespace1982 Not admitting that he has maybe make a mistake
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?
I don't know, but that code doesn't look anything at all like mine. Maybe start there.
Very helpful. Thanks you..... Hope continue.....
Glad you liked it...there's like 50 more videos in this playlist
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..
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.
Sir, Which type of editor do you use for programming in python ?
I use the sublime text editor and the git bash terminal
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
Complicated topic...I'll do some videos on it eventually.
Thank you
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):
Glad you got it sorted out
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.
Yes, you can make them into exe files. Check the playlist, I have a video on that
@@Codemycom Thanks a lot, i'll check it tomorrow.
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.
yeah
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
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...
@@Codemycom how do you know all this stuff? Thanks!
@@TakeMorePics lol no idea, haha
"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?
Don't use visual code
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.
it should be iconoprueba.ico not iconoprueba.icon, that's why you got an error.
@@Codemycom i still get it any solutions
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?
Nothing has changed, you're doing something wrong.
@@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
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.
@@maxwellhawk No clue, Pycharm sucks...I don't use or recommend it.
@@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.
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!
Is the file a real ico file?
i am having the same issue also, if anyone knows a fix or suggestion to fix this, would be greatly appreciated
@@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
Thanks it was great & very useful♥♥
You're welcome 😊
whn i try to run the pogram it says photoimage' object has no attribute '_photoimage__photo' any ideas what i should do??
Hello, I have got a problem. I am getting an error wich sais "No module named" PIL" I have already reinstalled Pillow multiple times.
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
try this before "python -m pip install --upgrade pip"
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.
And fyi i've already installed Pillow Function
Sir.what is the compiler u are using??
Pycharm
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()
Some people just have trouble with PIL, you'll have to google that error - there could be a dozen solutions.
@@Codemycom I tried a lot but couldn't fix it 😥😭
@@Codemycom I tried it in PyChram and it works! Dunno why it doesn't work in Sublime text
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
Check this out for your answer... stackoverflow.com/questions/33134594/set-tkinter-python-application-icon-in-mac-os-x
Those who are getting delayed by the exit button: You can use root.destroy instead of root.quit
thanks that really helped me but why didn't root.quit work ?🤔
Thankyou Man
@@ayaallahibrahimabdel-razek7971 maybe its kind of deprecated or something
Thank you
I done the same as 2:45
But it says can't deode bytes untruncated
Check your code for typos
good afternoon sir, i want to ask something about tkinter, can we display terminal python with it?
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
Thank you very much. I learnt a lot about tkinter. 🤭❤️
Glad it was helpful!
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.
did you pip install Pillow and import Image at the top of your file?
@@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!
@@aadityasahoo6244 Set it aside for a couple days and look at it with fresh eyes...you probably just misspelled something
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
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.
I love your videos. I learned a lot from them. More power to you!
Thanks!
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)
try installing it again
very very nice❣❣❣
thanks
im gonna be honest mr heisenberg you look extremely cute with the doggo
Ha thanks
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 ! :)
But when adding something happens in 10 seconds, for free...why does that bother you?
@@Codemycom Just a work in progress, then. :)
thanks a lot man!
Welcome!
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?
Don't use idle
@@Codemycom Does idle not support certain function? Or is not there some other way to perform the exit button function?
@@ritusree05 It's idle...why would you use it?
@@Codemycom OK then.... I will try not to use it any more. Thank you sir.
@@ritusree05 sir u can try using root.destroy in built function instead
Hello. I get AttributeError: 'PhotoImage' object has no attribute '_PhotoImage__photo'. Do you know what could be the problem?
looks like you have an error in your code.
how would you set the image in the top right? so it is always in the top right?
maybe check the video I have on status bars..it shows how to put stuff in the bottom right, and you can modify that
Is quit a built-in method for pyCharm IDE?
The IDE you use is irrelvant...we aren't writing code for an IDE...we're just writing Python code
you are really awesome, highly appreciate your work
Thank you! I appreciate that!
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
Yeah, I don't know how you can use a chromebook with tkinter
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
try lowercase c in c:/
that doesn't work either. Getting the same error.
@@333-n4q check your code for typos
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?
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
@@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.
@@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
@@douglasmonteiro3085 Awesome! Yeah I don't like pyCharm personally. I stick with Sublime Text and I never have a problem.
How can I resize the image?
Check the playlist, I have videos on that.
Is it possible that command=root.quit doesn't work on Mac?
it doesn't work in IDLE...but you shouldn't be using IDLE anyway
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?
use lowercase C
root.iconbitmap('c:/photos/red.ico')
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 😊
Sorry, I don't know Spyder but it gives a lot of people trouble. Why not use the free tools I use?
@@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!☹
@@pranavdabre1816 could be
@@Codemycom Sorry to bother you
You've just created a video on my issue 2 weeks ago!!😅😅
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!!!
sure
am using grid system, if i click the exit button the gui is not automatically closing can u hel me?
Has nothing to do with the grid system. You likely have a typo or did something different from the video. Try root.quit()
@@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
its working on visual studio code but not in python idle but thank u so much
Hello sir as you wrote the Image.open( " image1.png").. this portion is not working in my system..
No space after the " in "image1.png"
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
Yeah, there's nothing to all of that. I have videos on pretty much all of that in this playlist.
i installed pillow, but in python, it underlines PIL in red, and also ImageTk, and Image
After i have installed Pillow it still says "No module named 'PIL'" when i try running the program. Someone help?
Have you installed PILLOW?
same problem ,I installed pillow but it says no module PIL available
If you use “studio visual code” i Can help you guys
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.
Did you forget to put () on quit?
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
@@mdzohaib7368 Oh yeah, tkinter doesn't work in a python shell. Use the tools I do, sublime text and the git bash terminal.
I was facing the same problem too. But then, I used 'command=quit' and it worked for me
is there a way to make a back/reverse button in tkinter?
Sure...it just depends what you want to go back on
@@Codemycom Sir did you make a video for it, I have been searching through your series but I couldn't find any?
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?
You never want to put it all on one line...as you've discovered
if i wanted to randomly select 1 image from a bunch of images how would i go upon doing that
Add them all to a list and randomly select an item from the list in the normal way: random.choice(yourlist)
how can I print the output only once if I click a button widget?
Run an if statement in the function to see if the output has been printed already
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!
That's a blank app...what did you think would happen? remove the root.iconbitmap line
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?
This is ridiculous but is it important to put the root (root, text=" ") is there any effects if i delete it?
you need to put the root always.
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
You have a typo or something. What did you do differently than my code?
@@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'
@@rocketleagueshorts1961 Yep, exactly as I said. It's not Pictureimage, it's PhotoImage
@@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
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.
you might have a typo that you aren't noticing. Let me see your code..
@@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.
@@borgyoh you could copy and paste the code here
@@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()
@@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
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?
Windows icon files don't work on linux. You have to google linux icons for the solution
Walter White teaches Tkinter like a boss.
I'm getting an error
File "/Users/.../mu_code/gui tutorials/imagescode.py", line 9
my_label = Label(image=my_img)
^
SyntaxError: invalid syntax
l should be big L
You need to use a PhotoImage() class to do that:
Image = PhotoImage(file="Image.png")
Label(image = Image).pack()
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
in tkinter you don't use () to call functions.
When running the root.iconbitmap(file path) I get a TclError: bitmap not defined. Is the image faulty or is my code wrong?
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...
@@Codemycom I have tried this, there's one decent article on stackoverflow and I tried everything and still doesn't work.
@@tommajor4587 then maybe it is your image
@@Codemycom I have saved as .ico as a bitmap and a JPEG and even download GIMP to test, image is fine.
@@tommajor4587 try downloading an actual icon from the web and trying that.