ValueError:必须指定标题或 pageid

我一直在用 Python 3.8 编写代码来帮助我研究事物,我想把它变成一个 GUI。当我这样做时,每当我点击“开始”按钮时都会收到此错误。如果你们中的任何人看到错误,这里是代码。

# 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,15')).place(y = 250,x = 325)

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

    # Mainloop
    root.mainloop()

# Run Application
Application()
iCMS 回答:ValueError:必须指定标题或 pageid

您将 Term 传递给 wikipedia.summary()。错误来自 summary() 创建 page (code)。当没有有效的标题或页面 ID 传递给 page (code) 时,会发生此错误。在您的情况下会发生这种情况,因为您将 Term 直接传递给 summary(),而没有先将其转换为字符串。此外,Term 是一个 NoneType 对象,因为您实际上是将它设置为 place() 的结果。您必须在创建 Term 时存储 Entry(),然后对其应用 place 操作,以便能够保留对它的引用(请参阅 here为什么):

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

然后,您可以通过以下方式获取文本值:

Result = wikipedia.summary(Term.get())
本文链接:https://www.f2er.com/140132.html

大家都在问