猫史档案馆


【Python作品分享】tk版中英互译查询器【作品秀】

用户:Wallacep2071Wallacep2071查看:0 回复:0 评论:0 创建时间:2021-08-02T18:27:03


【作品展示】

center_image

 

【作品介绍】

tkinter版中英互译器

输入后按search

 

【作品源代码】

from tkinter import Tk, Entry, Button, StringVar, Label
from requests import post


def main():
    win = Tk()
    win.title("")
    win.geometry("250x250")
    entry = Entry()
    entry.pack()
    word_str = StringVar()

    def get(text_):
        post_url = "https://fanyi.喵/sug"
        data = {
            "kw": text_
        }
        head = {
            "User-Agent": "Mozilla/5.0"
        }
        x_ = post(post_url, data, headers=head).json()
        return x_

    def on():
        text = entry.get()
        x = get(text)
        li = 0
        word = ""
        for i in range(len(x["data"])):
            word += f"{x['data'][li]['k']}\n{x['data'][li]['v']}\n"
            li += 1
        word_str.set(word)
    Button(win, text="search", command=on).pack()
    Label(win, textvariable=word_str).pack()
    win.mainloop()


main()

 

【提示】

部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:

https://python.codemao.cn


回复

上一页1 页 / 共 0下一页