First Gui attempt and file not working like it is supposed to. - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: GUI (https://python-forum.io/forum-10.html) +--- Thread: First Gui attempt and file not working like it is supposed to. (/thread-7845.html) |
First Gui attempt and file not working like it is supposed to. - Tuck12173 - Jan-27-2018 Hi, I am sure this is something super easy and I am just a newb, but this is my first GUI and I can't even get the logo to appear. Here is my code and my file is in the same directory with my code. from tkinter import * root = Tk() photo = PhotoImage(file='dndlogo.jpg') logo = Label(root, image=photo) logo.pack() root.mainloop()This is the error I am getting. "C:\Users\Delusional Customer\venv\GM Screen\Scripts\python.exe" "C:/Users/Delusional Customer/PycharmProjects/DM Screen/MainScreen.py" Traceback (most recent call last): File "C:/Users/Delusional Customer/PycharmProjects/DM Screen/MainScreen.py", line 6, in <module> photo = PhotoImage(file='dndlogo.jpg') File "C:\Users\Delusional Customer\AppData\Local\Programs\Python\Python36-32\Lib\tkinter\__init__.py", line 3539, in __init__ Image.__init__(self, 'photo', name, cnf, master, **kw) File "C:\Users\Delusional Customer\AppData\Local\Programs\Python\Python36-32\Lib\tkinter\__init__.py", line 3495, in __init__ self.tk.call(('image', 'create', imgtype, name,) + options) _tkinter.TclError: couldn't recognize data in image file "dndlogo.jpg" Process finished with exit code 1 Also I was watching a tutorial on youtube and it still isn't working. Thanks in advance. Tuck RE: First Gui attempt and file not working like it is supposed to. - Larz60+ - Jan-27-2018 Quote:couldn't recognize data in image file "dndlogo.jpg"if using python 3, use: from PIL import ImageTk, Image photo = ImageTk.PhotoImage(Image.open('dndlogo.jpg')) logo = Label(root, image=photo)I think this will work with python 2 as well You may have to install pillow pip install pillow RE: First Gui attempt and file not working like it is supposed to. - Tuck12173 - Jan-28-2018 That worked out perfect, I had tried that previously and must have had a typo. Thanks. Tuck |