Python+tkinter實現(xiàn)制作文章搜索軟件
前言
無聊的時候做了一個搜索文章的軟件,有沒有更加的方便快捷不知道,好玩就行了
環(huán)境使用
Python 3.8
Pycharm
模塊使用
import requests
import tkinter as tk
from tkinter import ttk
import webbrowser
最終效果

界面實現(xiàn)代碼
導(dǎo)入模塊
import tkinter as tk from tkinter import ttk
創(chuàng)建窗口
root = tk.Tk()
root.title('問題搜索')
root.geometry('900x700+100+100')
root.iconbitmap('search.ico')
root.mainloop()

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

搜索框
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)

內(nèi)容顯示界面
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='發(fā)布時間')
tree_view.heading('link', text='鏈接')
tree_view.pack(fill=tk.BOTH, expand=True, pady=5)

內(nèi)容效果代碼
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):
# 往樹狀圖中插入數(shù)據(jù)
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)
# 往樹狀圖中插入數(shù)據(jù)
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])

到此這篇關(guān)于Python+tkinter實現(xiàn)制作文章搜索軟件的文章就介紹到這了,更多相關(guān)Python tkinter文章搜索內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
python數(shù)學(xué)建模(SciPy+?Numpy+Pandas)
這篇文章主要介紹了python數(shù)學(xué)建模(SciPy+?Numpy+Pandas),文章基于python的相關(guān)資料緊接上一篇文章內(nèi)容展開主題詳情,需要的小伙伴可以參考一下2022-07-07
Python實現(xiàn)復(fù)制文檔數(shù)據(jù)
我們百度搜索一些東西得時候,經(jīng)常找到文檔里面然后就會發(fā)現(xiàn)需要充值才能復(fù)制!怎么可以不花錢也保存呢?今天就分享給大家一個python獲取文檔數(shù)據(jù)得方法,需要的可以收藏一下2022-12-12
Python利用 SVM 算法實現(xiàn)識別手寫數(shù)字
支持向量機 (Support Vector Machine, SVM) 是一種監(jiān)督學(xué)習(xí)技術(shù),它通過根據(jù)指定的類對訓(xùn)練數(shù)據(jù)進行最佳分離,從而在高維空間中構(gòu)建一個或一組超平面。本文將介紹通過SVM算法實現(xiàn)手寫數(shù)字的識別,需要的可以了解一下2021-12-12
python人工智能tensorflow函數(shù)tensorboard使用方法
這篇文章主要為大家介紹了python人工智能tensorflow函數(shù)tensorboard使用方法,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-05-05

