Python+tkinter實(shí)現(xiàn)制作文章搜索軟件
前言
無(wú)聊的時(shí)候做了一個(gè)搜索文章的軟件,有沒(méi)有更加的方便快捷不知道,好玩就行了
環(huán)境使用
Python 3.8
Pycharm
模塊使用
import requests
import tkinter as tk
from tkinter import ttk
import webbrowser
最終效果
界面實(shí)現(xiàn)代碼
導(dǎo)入模塊
import tkinter as tk from tkinter import ttk
創(chuàng)建窗口
root = tk.Tk() root.title('問(wèn)題搜索') root.geometry('900x700+100+100') root.iconbitmap('search.ico') root.mainloop()
標(biāo)題圖片
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='問(wèn)題描述:', 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='序號(hào)') tree_view.heading('title', text='標(biāo)題') tree_view.heading('author', text='作者') tree_view.heading('date', text='發(fā)布時(shí)間') 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ù)狀圖中插入數(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ù)狀圖中插入數(shù)據(jù) show(search_list) # 單擊 獲取當(dāng)前點(diǎn)擊行的值 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實(shí)現(xiàn)制作文章搜索軟件的文章就介紹到這了,更多相關(guān)Python tkinter文章搜索內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
如何使用selenium和requests組合實(shí)現(xiàn)登錄頁(yè)面
這篇文章主要介紹了如何使用selenium和requests組合實(shí)現(xiàn)登錄頁(yè)面,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-02-02老生常談Python startswith()函數(shù)與endswith函數(shù)
下面小編就為大家?guī)?lái)一篇老生常談Python startswith()函數(shù)與endswith函數(shù)。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-09-09Python?列表中的刪除操作之del、remove?和?pop?的區(qū)別
在Python中,列表(list)是一種非常靈活的數(shù)據(jù)結(jié)構(gòu),它允許我們存儲(chǔ)一系列的元素,在刪除元素時(shí),我們可以使用三種不同的方法:del、remove?和?pop,每種方法都有其特定的用途和行為,了解它們的區(qū)別可以幫助我們更有效地使用列表,感興趣的朋友跟隨小編一起看看吧2024-05-05Python二叉樹(shù)定義與遍歷方法實(shí)例分析
這篇文章主要介紹了Python二叉樹(shù)定義與遍歷方法,結(jié)合實(shí)例形式分析了二叉樹(shù)的概念、原理及Python定義、遍歷二叉樹(shù)相關(guān)操作技巧,需要的朋友可以參考下2018-05-05python3 打印輸出字典中特定的某個(gè)key的方法示例
這篇文章主要介紹了python3 打印輸出字典中特定的某個(gè)key的方法,涉及Python字典的遍歷、判斷、輸出等相關(guān)操作技巧,需要的朋友可以參考下2019-07-07使用Pytorch Geometric進(jìn)行鏈接預(yù)測(cè)的實(shí)現(xiàn)代碼
PyTorch Geometric (PyG)是構(gòu)建圖神經(jīng)網(wǎng)絡(luò)模型和實(shí)驗(yàn)各種圖卷積的主要工具,在本文中我們將通過(guò)鏈接預(yù)測(cè)來(lái)對(duì)其進(jìn)行介紹,文中有詳細(xì)的代碼示例供大家參考,需要的朋友可以參考下2023-10-10python 畫(huà)三維圖像 曲面圖和散點(diǎn)圖的示例
今天小編就為大家分享一篇python 畫(huà)三維圖像 曲面圖和散點(diǎn)圖的示例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-12-12tensorflow入門(mén)之訓(xùn)練簡(jiǎn)單的神經(jīng)網(wǎng)絡(luò)方法
本篇文章主要介紹了tensorflow入門(mén)之訓(xùn)練簡(jiǎn)單的神經(jīng)網(wǎng)絡(luò)方法,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-02-02