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

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

前言

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

环境使用

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

标签:Python,tkinter,文章,搜索
0
投稿

猜你喜欢

  • asp 去除最后一个逗号为空字符串的代码

    2010-06-09 19:18:00
  • 详解在python操作数据库中游标的使用方法

    2024-01-27 10:51:41
  • 浅谈Scrapy框架普通反爬虫机制的应对策略

    2023-07-14 17:11:40
  • python 实现查找文件并输出满足某一条件的数据项方法

    2021-05-10 11:51:30
  • tensorflow 获取所有variable或tensor的name示例

    2021-04-02 22:29:54
  • Python数据传输黏包问题

    2023-04-21 13:05:22
  • python中使用多线程改进flask案例

    2022-11-07 05:44:55
  • 使用Python 统计文件夹内所有pdf页数的小工具

    2022-07-06 23:21:46
  • python Tensor和Array对比分析

    2023-08-27 04:37:02
  • python socket多线程通讯实例分析(聊天室)

    2022-11-21 13:18:58
  • PHP禁止页面缓存的代码

    2023-07-04 05:35:02
  • python命令行工具Click快速掌握

    2021-08-13 08:03:58
  • 关于浏览器地址栏的小图标favicon.ico制作

    2010-03-07 15:57:00
  • mysql 5.7更改数据库的数据存储位置的解决方法

    2024-01-21 11:56:43
  • 关于python 读取csv最快的Datatable的用法,你都学会了吗

    2022-02-22 20:38:32
  • 用asp给网站添加rss聚合功能

    2007-11-05 19:08:00
  • Django rstful登陆认证并检查session是否过期代码实例

    2022-11-04 16:17:15
  • jupyter notebook 自定义python解释器的过程详解

    2021-03-07 15:31:36
  • python 一维二维插值实例

    2022-07-17 10:09:08
  • $.browser.msie 为空或不是对象问题的多种解决方法

    2024-05-11 09:33:55
  • asp之家 网络编程 m.aspxhome.com