测试步骤:
运行程序:运行上述代码,输入一个词条(如“Python”)并点击“获取回答”按钮。
import tkinter as tk
from tkinter import filedialog, messagebox
import requests
from bs4 import BeautifulSoup
import json
import os
import threading
from tkinter import ttk
import logging
import time
import random # 导入随机模块
# 配置日志
logging.basicConfig(filename='app.log', level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
# 读取配置文件
CONFIG_FILE = 'config.json'
DEFAULT_CONFIG = {
"record_folder": "记录",
"log_file": "app.log"
}
def load_config():
if os.path.exists(CONFIG_FILE):
with open(CONFIG_FILE, 'r', encoding='utf-8') as file:
return json.load(file)
return DEFAULT_CONFIG
config = load_config()
class BaikeSearchApp:
def __init__(self, root):
self.root = root
self.root.title("百度百科查询工具")
# 创建输入框
self.input_frame = tk.Frame(root)
self.input_frame.pack(pady=5)
self.input_label = tk.Label(self.input_frame, text="输入问题:")
self.input_label.pack(side=tk.LEFT, padx=5)
self.input_entry = tk.Entry(self.input_frame, width=60)
self.input_entry.pack(side=tk.LEFT, padx=5)
self.clear_input_button = tk.Button(self.input_frame, text="清除", command=self.clear_input)
self.clear_input_button.pack(side=tk.LEFT, padx=5)
# 创建文本框
self.text_frame = tk.Frame(root)
self.text_frame.pack(pady=10)
self.text = tk.Text(self.text_frame, wrap='word', height=20, width=80)
self.text.pack(pady=10)
# 创建按钮
self.button_frame = tk.Frame(root)
self.button_frame.pack(pady=5)
self.load_button = tk.Button(self.button_frame,<
标签:百科,self,搜集,text,015,import,input,frame,tk
From: https://blog.csdn.net/weixin_54366286/article/details/144290698