KeyError raised when attempting to use Tkinter entry to call a request

I'm fairly new to programming and Python in general. I'm attempting to use Tkinter to build a bible app for my mom as a present of sorts for mothers day, however I'm mainly using this project as a means to practice and develop new skills. I'm using the bible-api and JSON to return the requested verse (For example 3:16 will return said verse). However, whenever I attempt to run the program, I receive a key error, in specific "KeyError: 'text'" with a traceback to lines 21 and 8. Code is as follows:

import json
import requests
from tkinter import *
def printVerse():
    verse_input = entry.get()
    verse_raw = requests.get('' + verse_input).json()
    verse_text = verse_raw['text']
    verse_output = Label(root, text=verse_text)

root = Tk()
root.title('Bible App')


entry = Entry(root)
entry.insert(0, "Ex. 'John 3:16'")
entry.pack(padx=5, pady=5)

return_button = Button(root, text='Print Your Verse!', command=printVerse())


Whenever I replace entry.get() with a regular string the program executes with no issues. I've also tried adding a textvariable to Entry(root) and using the .get command on the entry variable, however that returns the same error. What am I doing wrong here?

Thanks in advance.

Read more here:

Content Attribution

This content was originally published by Charnebald at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: