-1

The code displayed below is giving me a ValueError, explaining I need a title or pagid specified. I have checked the code over and over and do not see a problem. Please let me know if you have any idea what I am doing wrong.

This code is meant to give me information about most key words I enter. If I want Jeff Bezos, information will be printed to the console.

# Imports
import wikipedia
from tkinter import *
import time

# Code
def Application():
    # Definitions
    def Research():
        # Defines Entry
        Result = wikipedia.summary(Term)

        print(Result)

    # Window Specifications
    root = Tk()
    root.geometry('900x700')
    root.title('Wikipedia Research')

    # Window Contents
    Title = Label(root, text = 'Wikipedia Research Tool', font = ('Arial', 25)).place(y = 10, x = 250)

    Directions = Label(root, text = 'Enter a Term Below', font = ('Arial, 15')).place(y = 210, x = 345)

    Term = Entry(root, font = ('Arial, 15')).place(y = 250, x = 325)

    Run = Button(root, font = ('Arial, 15'), text = 'Go', command = Research).place(y = 300, x = 415)

    # Mainloop
    root.mainloop()

# Run Application
Application()
brrrrrrrt
  • 51
  • 2
  • 13

1 Answers1

5

You're passing Term to wikipedia.summary(). The error is coming from when summary() creates a page (code). This error happens when there is no valid title or page ID being passed to the page (code). This is happening in your case because you're passing Term straight to summary(), without first converting it to a string. Additionally, Term is a NoneType object, because you're actually setting it to the result of place(). You have to store Term when you create the Entry(), and then apply the place operation to it, in order to be able to keep a reference to it (see here for why):

Term = Entry(root, font = ('Arial, 15'))
Term.place(y = 250, x = 325)

Then, you can get the text value via:

Result = wikipedia.summary(Term.get())
Random Davis
  • 6,662
  • 4
  • 14
  • 24
  • 1
    Don't forget to mention [this](https://stackoverflow.com/questions/1101750/tkinter-attributeerror-nonetype-object-has-no-attribute-attribute-name) problem :D – TheLizzard Jul 06 '21 at 16:41
  • Thanks so much! I honestly forgot about the '.get()' function! – brrrrrrrt Jul 06 '21 at 16:56
  • 2
    @brrrrrrrt no problem, and also keep in mind that `get()` won't work without first making sure `Term` is set to the result of `Entry()` rather than `place()`. – Random Davis Jul 06 '21 at 16:56
  • @RandomDavis I do not really understand that, can you elaborate? – brrrrrrrt Jul 06 '21 at 16:58
  • 2
    `Term.get()` is the fix, but it won't work unless you also separate `Term = Entry(...).place(...)` into two separate lines, like I showed in my example. See the link in @TheLizzard's comment for an explanation of why. – Random Davis Jul 06 '21 at 17:07