0

I am learning how to use Tkinter to create GUI. I learnt using the video from https://www.youtube.com/watch?v=_lSNIrR1nZU. I was able recreate the glossary as in the video. My Problem now is; after compiling the python script with pyinstaller to make it an executable file, the app does not run(it says it can't load the image), but if I comment out the line of code for the image and I recompile it with pyinstaller, the app runs as an executable file.
PS: You can use any image but name it "me.gif" and it should be in same working directory as script.
How do I make the image load after compiling the script with pyinstaller?

This is the code:

from tkinter import *

def click ():
    entered_text = textentry.get() 
    output.delete(0.0, END)
    try:
        definition = my_compdictionary[entered_text]
    except:
        definition = "sorry there is no word like that please try again"
    output.insert (END, definition)

window = Tk()
window.title("My Dictionary")
window.configure(background="black")

photo1 = PhotoImage(file="me.gif")
Label (window, image=photo1, bg="black") .grid (row=0, column=0, sticky=E)

Label (window, text="Enter the word you would like a definition for:", bg="black", fg="white", font="none 12 bold") .grid(row=1, column=0, sticky=W)

textentry = Entry (window, width=20, bg="white")
textentry.grid (row=2, column=0, sticky=W)

Button(window, text="SUBMIT", width=6, command=click) .grid (row=3, column=0, sticky=W)

Label (window, text="\nDefinition:", bg="black", fg="white", font="none 12 bold") .grid(row=4, column=0, sticky=W)

output = Text (window, width=75, height=6, wrap=WORD, background="white")
output.grid(row=5, column=0, columnspan=2, sticky=W)

my_compdictionary = {'algorithm': 'step by step instructions to complete a task', 'bug': 'piece of code that causes a program to fail'}

Label (window, text="click to exit:", bg="black", fg="white", font="none 12 bold") .grid(row=6, column=0, sticky=W)

def close_window ():
    window.destroy()
    exit()

Button(window, text="Exit", width=14, command=close_window) .grid(row=7, column=0, sticky=W)

window.mainloop()
Nerdd
  • 53
  • 3
  • 7
  • place the image in the folder you have you `exe` file – AD WAN Nov 27 '18 at 12:35
  • Related: https://stackoverflow.com/questions/31836104/pyinstaller-and-onefile-how-to-include-an-image-in-the-exe-file – fhdrsdg Nov 27 '18 at 13:57
  • @ AD WAN: I did place the image in the folder I have the exe file, it still does not work. Am on Mac OS X 10.11 – Nerdd Nov 29 '18 at 12:31

0 Answers0