|
|
|
@ -0,0 +1,42 @@
|
|
|
|
|
# ui.py 文件
|
|
|
|
|
import tkinter as tk # 导入Tkinter库,用于GUI开发 [2](@ref)
|
|
|
|
|
import threading # 导入多线程模块,实现后台计算 [3](@ref)
|
|
|
|
|
import sys # 导入系统模块,用于路径管理 [2](@ref)
|
|
|
|
|
sys.path.append(r"./datas") # 将当前目录下的'one'文件夹加入模块搜索路径 [2](@ref)
|
|
|
|
|
from calculate import * # 动态导入b.py中的main函数,实现功能解耦 [2](@ref)
|
|
|
|
|
|
|
|
|
|
class GUI:
|
|
|
|
|
def __init__(self):
|
|
|
|
|
self.root = tk.Tk() # 创建Tkinter主窗口对象 [2](@ref)
|
|
|
|
|
self.root.title('演示窗口') # 设置窗口标题 [2](@ref)
|
|
|
|
|
self.root.geometry("2500x560") # 设置窗口大小和位置 [2](@ref)
|
|
|
|
|
self.interface() # 调用界面布局方法 [2](@ref)
|
|
|
|
|
|
|
|
|
|
def interface(self):
|
|
|
|
|
""""界面编写位置"""
|
|
|
|
|
self.Button0 = tk.Button(self.root, text="确定查询", command=self.start, bg="#7bbfea") # 创建按钮控件 [2](@ref)
|
|
|
|
|
self.Button0.grid(row=0, column=1, pady=10,ipadx=25) # 使用grid布局管理器定位按钮 [2](@ref)
|
|
|
|
|
#command=self.start实现按钮点击事件绑定,避免直接操作主循环 。
|
|
|
|
|
#pady=10设置组件垂直间距,提升界面美观度
|
|
|
|
|
self.entry00 = tk.StringVar() # 创建字符串变量,用于数据绑定 [2](@ref)
|
|
|
|
|
self.entry00.set("") # 初始化变量值为空字符串
|
|
|
|
|
self.entry0 = tk.Entry(self.root, textvariable=self.entry00) # 创建输入框并绑定变量 [2](@ref)
|
|
|
|
|
self.entry0.grid(row=1, column=1, pady=15,sticky='n') # 布局输入框
|
|
|
|
|
'''
|
|
|
|
|
self.w1 = tk.Text(self.root, width=50, height=8) # 创建多行文本显示区域 [2](@ref)
|
|
|
|
|
self.w1.grid(row=2, column=0, columnspan=3, padx=60) # 布局文本区域
|
|
|
|
|
'''
|
|
|
|
|
self.result_label = tk.Label(self.root, text="查询结果将显示这里")
|
|
|
|
|
self.result_label.grid(row=3, column=0, columnspan=3)
|
|
|
|
|
|
|
|
|
|
def start(self):
|
|
|
|
|
isbn = self.entry00.get()
|
|
|
|
|
# 直接调用同步函数
|
|
|
|
|
result = query_isbn(isbn)
|
|
|
|
|
# 更新界面显示
|
|
|
|
|
self.result_label.config(text=result)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
a = GUI()
|
|
|
|
|
a.root.mainloop()
|