首页 > 其他分享 >GUI

GUI

时间:2023-12-17 20:59:58浏览次数:25  
标签:name GUI tk query entry root class

import pandas as pd
import tkinter as tk
from tkinter import messagebox

# 创建数据库表
# Excel表中必须包含学号、班级、姓名这三列
class_info = pd.read_excel('students.xlsx')

# 创建GUI程序
root = tk.Tk()
root.title('班级信息收集')

# 设置窗口大小
window_width = 400
window_height = 300

# 获取屏幕宽度和高度
screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()

# 计算窗口居中时的位置
x = (screen_width - window_width) // 2
y = (screen_height - window_height) // 2

# 设置窗口初始位置和大小
root.geometry(f'{window_width}x{window_height}+{x}+{y}')


# 注册函数
def register():
global class_info
student_id = entry_id.get()
class_name = entry_class.get()
student_name = entry_name.get()

if not student_id or not class_name or not student_name:
messagebox.showerror('错误', '请填写完整信息')
else:
# 检查学号是否已存在
if student_id in class_info['学号'].values:
messagebox.showerror('错误', '该学号已被注册')
else:
# 添加新记录
new_record = pd.DataFrame({'学号': [student_id], '班级': [class_name], '姓名': [student_name]})
class_info = class_info._append(new_record, ignore_index=True)
messagebox.showinfo('成功', '注册成功')
class_info.to_excel('students.xlsx', index=False)


# 查询函数
def query():
student_name = entry_query_name.get()
class_name = entry_query_class.get()
if not class_name or not student_name:
messagebox.showerror('错误', '请填写完整信息')
else:
result = class_info[(class_info['姓名'] == student_name) & (class_info['班级'] == class_name)]['学号']
if len(result) == 0:
messagebox.showinfo('查询结果', '未找到该同学')
else:
messagebox.showinfo('查询结果', f'学号为: {result.values[0]}')


# 创建注册表单
label_id = tk.Label(root, text='学号', font=('Arial', 12), padx=10, pady=5)
label_id.grid(row=0, column=0)
entry_id = tk.Entry(root, font=('Arial', 12))
entry_id.grid(row=0, column=1)

label_class = tk.Label(root, text='班级', font=('Arial', 12), padx=10, pady=5)
label_class.grid(row=1, column=0)
entry_class = tk.Entry(root, font=('Arial', 12))
entry_class.grid(row=1, column=1)

label_name = tk.Label(root, text='姓名', font=('Arial', 12), padx=10, pady=5)
label_name.grid(row=2, column=0)
entry_name = tk.Entry(root, font=('Arial', 12))
entry_name.grid(row=2, column=1)

button_register = tk.Button(root, text='注册', font=('Arial', 12), bg='white', fg='black', command=register)
button_register.grid(row=3, column=0, columnspan=2, padx=10, pady=5)

# 创建查询表单
label_query_class = tk.Label(root, text='查询班级', font=('Arial', 12), padx=10, pady=5)

label_query_class.grid(row=4, column=0)
entry_query_class = tk.Entry(root, font=('Arial', 12))
entry_query_class.grid(row=4, column=1)

label_query_name = tk.Label(root, text='查询姓名', font=('Arial', 12), padx=10, pady=5)
label_query_name.grid(row=5, column=0)
entry_query_name = tk.Entry(root, font=('Arial', 12))
entry_query_name.grid(row=5, column=1)

button_query = tk.Button(root, text='查询', font=('Arial', 12), bg='white', fg='black', command=query)
button_query.grid(row=6, column=0, columnspan=2, padx=10, pady=5)

root.mainloop()

 

标签:name,GUI,tk,query,entry,root,class
From: https://www.cnblogs.com/yxx0818/p/17909763.html

相关文章

  • GUI程序设计--班级信息收集系统
    因为没学过SQLandAccess的连接太麻烦了,所以是直接使用pandas库读写Excel文件的方法importpandasaspdimporttkinterastkfromtkinterimportmessagebox#创建数据库表#Excel表中必须包含学号、班级、姓名这三列class_info=pd.read_excel('students.xlsx')#创......
  • 超级好用的 HBase GUI 工具分享
    超级好用的HBaseGUI工具分享你是否曾为HBase数据管理而苦恼?别担心,这一款超级好用的HBaseGUI(HBaseAssistant)工具,让您在大数据世界中游刃有余。不再需要繁琐的命令行操作,也不再为复杂的配置感到头疼。主要功能直观和设计完善的图形用户界面,让您轻松应对数据库管理和开......
  • unigui显示uniTreeVview使用TUniTreeNode内存泄漏的问题【14】
    uniTreeVviewc创建一个tree,显示患者姓名(PatientName)。因为需要用到患者ID(PatientID),所以使用help:TPatientTreeNode=class(TUniTreeNode)//strictprivateFPatientID:string;functionGetPatientID:string;procedureSetPatientID(constValue:string)......
  • Guide to Arduino & Secure Digital (SD) Storage.
    原文:https://docs.arduino.cc/learn/programming/sd-guideHardware&SoftwareRequiredArduinoBoardwithSDCardSlot*ArduinoIDE(online or offline).FormattedSDCard*Theboards/shieldsthathaveanSDcardslotarelistedbelow:MKRZeroMKRIoT......
  • 将开源免费进行到底,ThreadX开源电脑端GUIBuilder图形开发工具GUIX Studio
    上个月微软刚刚宣布将ThreadXRTOS全家桶贡献给Eclipse基金会,免费供大家商用,宽松的MIT授权方式,就差这个GUIXStudio没有开源了,而且Windows还经常检索不到,并且也不提供离线包。1、软件包有点大,700MB,直接分享到百度云了:链接:https://pan.baidu.com/s/1tS8IDWrIXGiCTbHxwxEkDA  提......
  • Unity3D ugui适配iPhoneX的齐刘海屏幕详解
    Unity3D是一款强大的游戏开发引擎,广泛应用于手机游戏开发。随着苹果推出了iPhoneX,这款全面屏手机的出现给游戏开发者带来了新的适配问题。本文将详解如何在Unity3D中适配iPhoneX的齐刘海屏幕,并给出相应的技术详解和代码实现。对啦!这里有个游戏开发交流小组里面聚集了一帮热爱学习......
  • 【GUI软件】小红书搜索结果批量采集,支持多个关键词同时抓取!
    目录一、背景介绍1.1爬取目标1.2演示视频1.3软件说明二、代码讲解2.1爬虫采集模块2.2软件界面模块2.3日志模块三、获取源码及软件一、背景介绍1.1爬取目标您好!我是@马哥python说,一名10年程序猿。我用python开发了一个爬虫采集软件,可自动按关键词抓取小红书笔记数据。......
  • 使用Python和Qt6(PySide6)创建GUI应用1简介
    1简介在本书从GUI开发的基本原理逐步过渡到使用PySide6创建您自己的、功能齐全的桌面应用程序。1.1GUI简史图形用户界面(GUIGraphicalUserInterface)历史悠久,可追溯到20世纪60年代。斯坦福大学的NLS(ON-Line系统引入了鼠标和窗口概念,并于1968年首次公开展示。随后,施乐公司......
  • pyautogui.locateOnScreen()函数
    如何在屏幕上搜索某个图像假设桌面有个熟悉的图标如下:我们该如何用pyautogui找到它呢?如果是你,你该怎么找呢?是不是首先得参照上面这个图片,然后在屏幕上逐行扫描,扫到为止。pyautogui也是类似的:#图像识别(一个)oneLocation=pyautogui.locateOnScreen('weixin.png')print(on......
  • 在Windows 10上安装和配置EasyGUI库的步骤
     EasyGUI是一个方便易用的Python库,可以帮助开发者快速构建图形用户界面(GUI)应用程序。下面是在Windows10上安装和配置EasyGUI库的步骤: 1.安装Python: 首先,确保你的Windows10系统已经安装了Python解释器。 2.安装pip: 在Windows10上,可以通过以下步骤安装pip包管理器: -打开命......