#! /usr/bin/python3 # ================================================================== # Computer Science Glossary Project # # ------------------------------------------------------------------ # From: # # https://www.youtube.com/watch?v=_lSNIrR1nZU # # ------------------------------------------------------------------ # Possible Changes: # # a. replace the 'submit' field/button with a pulldown list # b. on startup (or do it with a button) randomly select a # definition to display # c. Read definitions from a file # # ================================================================== from tkinter import * # the dictionary my_compdictionary = { 'algorithm': 'step by step instructions to complete a task', 'bug': 'piece of code that causes a program to fail' } # submit button function # (this will collect the text from the entry box and use it to # access the dictionary) 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) # exit button function def close_window(): window.destroy() exit() #### main windown window = Tk() window.title('My Computer Science Glossary') window.configure(background='black') # my photo photo1 = PhotoImage(file='glossary.png') Label(window,image=photo1,bg='black').grid(row=0,column=0,sticky=E) # create label Label(window,text='Enter the work you would like a definition of:', bg='black',fg='white',font='none 12 bold').grid(row=1, column=0,sticky=W) # create text entry box textentry = Entry(window, width=20,bg='white') textentry.grid(row=2,column=0,sticky=W) # add submit button Button(window,text='Submit',width=5,command=click).grid(row=3, column=0,sticky=W) # create another label Label(window,text='\nDefinition:', bg='black',fg='white',font='none 12 bold').grid(row=4, column=0,sticky=W) # create a text box output = Text(window,width=75,height=6,wrap=WORD,background='white') output.grid(row=5,column=0,columnspan=2,sticky=W) # exit label Label(window,text='click to exit',bg='black',fg='white', font='none 12 bold').grid(row=6,column=0,sticky=W) # exit button Button(window,text='Exit',width=14,command=close_window).grid(row=7, column=0,sticky=W) #### main loop window.mainloop()