Python Forum
First Gui attempt and file not working like it is supposed to.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
First Gui attempt and file not working like it is supposed to.
#1
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
Reply
#2
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
Reply
#3
That worked out perfect, I had tried that previously and must have had a typo.

Thanks.

Tuck
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] What is $DISPLAY supposed to be? amethyst 2 2,468 Jun-29-2019, 04:36 PM
Last Post: amethyst
  Is self supposed to be here or not? iFunKtion 3 3,946 Feb-07-2017, 02:12 PM
Last Post: iFunKtion

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020