Python Forum

Full Version: First Gui attempt and file not working like it is supposed to.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
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
That worked out perfect, I had tried that previously and must have had a typo.

Thanks.

Tuck