使用 def 和 tkinter 在 python 中制作简单的维基百科应用程序

编程入门 行业动态 更新时间:2024-10-25 16:21:23
本文介绍了使用 def 和 tkinter 在 python 中制作简单的维基百科应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我是 Python 初学者.我正在尝试制作一个 python wiki 应用程序,它可以为您提供您搜索的任何内容的摘要.我的代码如下:

I am beginner in python. I am trying to make a python wiki app that gives you a summary of anything that you search for. My code is below:

import wikipedia


    question = input("Question: ")
    wikipedia.set_lang("en" )
    print (wikipedia.summary(question) )

此代码有效,但我想将 tkinter GUI 添加到带有输入字段和搜索按钮的应用程序.搜索结果将显示在 GUI 中的文本框中.

This code works but I want to add a tkinter GUI to the app with an entry field and a search button. The result of the search will then be displayed in the GUI in a text box.

推荐答案

假设你真的做了研究并且结果是空的(这是极不可能的),你可以使用类似的东西

assuming you really did research and came out empty(which is highly unlikely),you could use something like

from tkinter import *
import wikipedia

def on_click():
  q = get_q.get()
  text.insert(INSERT, wikipedia.summary(q))

root = Tk()
question = Label(root, text="Question")
question.pack()
get_q = Entry(root, bd =5)
get_q.pack()
submit = Button(root,text='Submit',command=on_click)
submit.pack()
text = Text(root)
text.pack()

root.mainloop()

尝试进行更多研究并阅读文档,他们是你最好的编程朋友

Do try to research more and readthedocs,they are your best friend in programming

这篇关于使用 def 和 tkinter 在 python 中制作简单的维基百科应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-30 05:36:35,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1390111.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   维基百科   简单   def   tkinter

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!