网络编程
位置:首页>> 网络编程>> Python编程>> Python+tkinter实现制作文章搜索软件

Python+tkinter实现制作文章搜索软件

作者:松鼠爱吃饼干  发布时间:2021-02-01 15:11:05 

标签:Python,tkinter,文章,搜索

前言

无聊的时候做了一个搜索文章的软件,有没有更加的方便快捷不知道,好玩就行了

环境使用

Python 3.8

Pycharm

模块使用

import requests

import tkinter as tk

from tkinter import ttk

import webbrowser

最终效果

Python+tkinter实现制作文章搜索软件

界面实现代码

导入模块

import tkinter as tk
from tkinter import ttk

创建窗口

root = tk.Tk()
root.title('问题搜索')
root.geometry('900x700+100+100')
root.iconbitmap('search.ico')

root.mainloop()

Python+tkinter实现制作文章搜索软件

标题图片

img = tk.PhotoImage(file='封面.png')
tk.Label(root, image=img).pack()

Python+tkinter实现制作文章搜索软件

搜索框

search_frame = tk.Frame(root)
search_frame.pack(pady=10)
search_va = tk.StringVar()
tk.Label(search_frame, text='问题描述:', font=('黑体', 15)).pack(side=tk.LEFT, padx=5)
tk.Entry(search_frame, relief='flat', width=30, textvariable=search_va).pack(side=tk.LEFT, padx=5, fill='both')
tk.Button(search_frame, text='搜索一下', font=('黑体', 12), relief='flat', bg='#fe6b00').pack(side=tk.LEFT,padx=5)

Python+tkinter实现制作文章搜索软件

内容显示界面

tree_view = ttk.Treeview(root, show="headings")

tree_view.column('num', width=1, anchor='center')
tree_view.column('title', width=150, anchor='w')
tree_view.column('author', width=10, anchor='center')
tree_view.column('date', width=10, anchor='center')
tree_view.column('link', width=30, anchor='center')
tree_view.heading('num', text='序号')
tree_view.heading('title', text='标题')
tree_view.heading('author', text='作者')
tree_view.heading('date', text='发布时间')
tree_view.heading('link', text='链接')

tree_view.pack(fill=tk.BOTH, expand=True, pady=5)

Python+tkinter实现制作文章搜索软件

内容效果代码

def search(word):
   search_list = []
   num = 0
   for page in range(1, 4):
       url = 'https://so.csdn.net/api/v3/search'
       data = {
           'q': word,
           't': 'all',
           'p': page,
           's': '0',
           'tm': '0',
           'lv': '-1',
           'ft': '0',
           'l': '',
           'u': '',
           'ct': '-1',
           'pnt': '-1',
           'ry': '-1',
           'ss': '-1',
           'dct': '-1',
           'vco': '-1',
           'cc': '-1',
           'sc': '-1',
           'akt': '-1',
           'art': '-1',
           'ca': '-1',
           'prs': '',
           'pre': '',
           'ecc': '-1',
           'ebc': '-1',
           'urw': '',
           'ia': '1',
           'dId': '',
           'cl': '-1',
           'scl': '-1',
           'tcl': '-1',
           'platform': 'pc',
       }
       headers = {
           'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36'
       }
       response = requests.get(url=url, params=data, headers=headers)
       for index in response.json()['result_vos']:
           title = index["title"].replace('<em>', '').replace('</em>', '')
           dit = {
               'num': num,
               'title': title,
               'author': index['nickname'],
               'date': index['create_time_str'],
               'link': index['url'],
           }
           num += 1
           search_list.append(dit)
   return search_list

def show(search_list):
   # 往树状图中插入数据
   for index, stu in enumerate(search_list):
       tree_view.insert('', index + 1,
                        values=(stu['num'], stu['title'], stu['author'], stu['date'], stu['link']))

def click():
   key_word = search_va.get()
   if key_word:
       search_list = search(word=key_word)
       # 往树状图中插入数据
       show(search_list)

# 单击 获取当前点击行的值
def tree_view_click(event):
   # 遍历选中的元素
   for item in tree_view.selection():
       # 获取选中元素的值
       item_text = tree_view.item(item, "values")
       # 打印选中元素的值
       # print(item_text)
       webbrowser.open(item_text[-1])

Python+tkinter实现制作文章搜索软件

来源:https://www.cnblogs.com/qshhl/p/16769135.html

0
投稿

猜你喜欢

  • pyenv简单介绍在日常运维中, 经常遇到这样的情况: 系统自带的Python是2.x,而业务部署需要Python 3.x 环境, 此时需要
  • 一、软件测试大型软件系统的开发是一个很复杂的过程,其中因为人的因素而所产生的错误非常多,因此软件在开发过程必须要有相应的质量保证活动,而软件
  • 本文实例总结了php处理json格式数据的方法。分享给大家供大家参考,具体如下:1.json简介:何为json?简 单地说,JSON 可以将
  • ubuntu 系统自带的 python 有多个版本,使用时难免会遇到环境变量出错,特别是当自动化运行脚本的时候。特别是近一个月来,实验室的小
  • 安装anaconda 是自动集成的如果导入不存在,直接pippip install tqmd参数#参数介绍iterable=None,des
  • 今天下午在练习python时用了“if...if...else...”的分支结构,结果运行出来吓我一跳。原来我想当然的认为“if...if.
  • 前言React核心的单向数据流、一切皆数据的state、不会改变的props,以及状态提升等等经常使用便不多总结,需要的看官方文档。JSXJ
  • 本文实例为大家分享了python实现五子棋小游戏的具体代码,供大家参考,具体内容如下暑假学了十几天python,然后用pygame模块写了一
  • 简介 函数式编程语言在学术领域已经存在相当长一段时间了,但是从历史上看,它们没有丰富的工具和库可供使用。随着 .NET 平台上的
  • 这里再重复一下标题为什么是"使用"而不是"实现":首先,专业人士提供的算法比我们自己写的算法无论是效
  • 很多时候,我们都在说设计需要引导用户,尤其是在对初级用户的引导上,很大程度决定着产品能否快速聚拢用户的可能;但同样很多时候,用户并不需要引导
  • 使用数据库的过程中,由于断电或其他原因,有可能导致数据库出现一些小错误,比如检索某些表特别慢,查询不到符合条件的数据等。出现这些情况的原因,
  • 用HZHOST实用工具集的服务器安全设置里安装了MSSQL安全配置,现在SQL2000还原不了数据库了,从还原选定设备浏览文件夹时出现&qu
  • Python面向对象编程(一)Python面向对象编程(二)Python面向对象编程(三)和其它编程语言相比,Python 在尽可能不增加新
  • 功能: 1、 允许/限制对表的修改 2、 自动生成派生列,比如自增字段 3、 强制数据一致性 4、 提供审计和日志记录 5、 防止无效的事务
  • asp+js做的一个dig程序中的投票(有的叫顶一下,踩一下),由于代码较长,只贴出核心部分:投票中的代码相关文章推荐:ajax +asp
  • 使用json.dumps输出中文在使用json.dumps时要注意一个问题>>> import json>>&
  • 本文实例讲述了Python实现的企业粉丝抽奖功能。分享给大家供大家参考,具体如下:一 代码def scode9(schoice): &nbs
  • 当创建一个Models, 在同步到数据库里,django默认设置了三个权限 ,就是 add, change, delete权限。但是往往有时
  • 目录一、网址分析二、代码编写三、遇到的问题1. 获取评论的时候也将子评论爬虫进去了。2. 获取全部评论数,直接通过 requests 获取不
手机版 网络编程 asp之家 www.aspxhome.com