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()