0

I am building a Tkinter App. You can enter a query and python will look for that key in a .json file. I want to get the value of the textEntry box and store it as the query variable, but instead I get null as the variable and I cannot enter a new query and search for something else.

from tkinter import *
import json

def searchDict():
    with open("database.json", "r") as read_file:
        query = textEntry.get()
        data = json.load(read_file)
        print(data.get(query))

root=Tk()
root.geometry('800x600')
root.title("Dictionary of Information yes")

introduction = Label(root, text="This is a Dictionary of People and info about them! please dont arrest me")
entertext = Label(root, text="Enter the name here: ")
textEntry = Entry(root)
query = textEntry.get()
buttonEntry = Button(root, text="Search", command=searchDict())
resultBox = Text(root, width=250, height=100)

introduction.pack()
entertext.pack()
textEntry.pack()
buttonEntry.pack()
resultBox.pack()

root.mainloop()
  • What have you done to debug this? Have you verified `query` is what you think it should be immediately prior to using it? Have you verified that `data` is what you think it should be immediately prior to using it? – Bryan Oakley Nov 04 '20 at 16:54
  • Data is supposed to be my json data, which acts as a dictionary, and query is supposed to be the user input from the Entry Box in the Tkinter GUI –  Nov 04 '20 at 17:09
  • I didn't ask what it's _supposed_ to be. I asked if you _verified_ that it is _actually_ what you're assuming it is. – Bryan Oakley Nov 04 '20 at 17:16
  • data is the json dictionary, but query is just a null value because when the function is running the Entry Box has no text in it –  Nov 04 '20 at 17:22

0 Answers0