Python beginner with little tkinter or OOP experience.
Functional code from a tkinter youtube tutorial, which called all tkinter functions globally, copied and modified into seperate functions. Code now calls functions immediately upon start. Photo no longer displays if exit button is commented. What am I missing?
#simple glossary example demonstrating tkinter basics
#program broken by adding main and attempting to partition into seperate functions
from tkinter import *
dictionary_db = {
'algorithm' : 'Algorithm: Step by step instructions to complete a task.',
'bug' : 'Bug: Piece of code that causes a program to fail.'
}
photo_file_name = "logo.png"
#click function used by submit button
def click(text_entry, output):
entered_text = text_entry.get()
output.delete(0.0, END)
try:
definition = dictionary_db[entered_text]
except:
definition = "Sorry not an exisiting word. Please try again."
output.insert(END, definition)
#exit function used by exit button
def close_window(window):
window.destroy()
exit()
#configure window
def config(window):
# config
window.title("My tkinter demo")
window.configure(background="black")
#create objects
photo1 = PhotoImage(file=photo_file_name)
photo_label = Label (window, image=photo1, bg="black")
entry_label = Label(window, text="Enter the word you would like a definition for: ", bg="black", fg="white", font="none 12 bold")
text_entry = Entry(window, width=20, bg="white")
output = Text(window, width=75, height=6, wrap=WORD, background="white")
submit_button = Button(window, text="SUBMIT", width=6, command=click(text_entry, output))
definition_label = Label (window, text="\nDefinition", bg="black", fg="white", font="none 12 bold")
exit_label = Label (window, text="click to exit", bg="black", fg="white", font="none 12 bold")
exit_button = Button(window, text="Exit", width=6, command=close_window(window))
#place objects
photo_label.grid(row=0, column=0, sticky=E)
entry_label.grid(row=1, column=0, sticky=W)
text_entry.grid(row=2, column=0, sticky=W)
submit_button.grid(row=3, column=0, sticky=W)
definition_label.grid(row=4, column=0, sticky=W)
output.grid(row=5, column=0, columnspan=2, sticky=W)
exit_label.grid(row=6, column=0, sticky=W)
exit_button.grid(row=7, column=0, sticky=W)
#main
def main():
window = Tk()
config(window)
window.mainloop()
if __name__ == '__main__':
main()
'''