|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
import tkinter as tk
from tkinter import messagebox
# 创建登录窗口
login_window = tk.Tk()
login_window.title("学生会管理系统")
login_window.geometry("260x150")
# 创建用户名和密码的标签和输入框
username_label = tk.Label(login_window, text="用户名:")
username_label.grid(row=0, column=0, padx=10, pady=10) # 设置Label的位置
username_entry = tk.Entry(login_window)
username_entry.grid(row=0, column=1, padx=10, pady=10) # 设置Entry的位置
password_label = tk.Label(login_window, text="密码:")
password_label.grid(row=1, column=0, padx=10, pady=10) # 设置Label的位置
password_entry = tk.Entry(login_window, show="*")
password_entry.grid(row=1, column=1, padx=10, pady=10) # 设置Entry的位置
def login():
username = username_entry.get() # 获取用户名输入框中的值
password = password_entry.get() # 获取密码输入框中的值
if username == "1" and password == "1":
# 销毁登录窗口
login_window.destroy()
# 创建部门主窗口
department_window = tk.Tk()
department_window.title("学生会管理系统")
department_window.geometry("260x270")
# 创建按钮
button1 = tk.Button(department_window, text="督察部", width=10, height=2)
button1.grid(row=0, column=0, pady=10, padx=20)
button2 = tk.Button(department_window, text="劳动部", width=10, height=2)
button2.grid(row=0, column=1, pady=10, padx=20)
button3 = tk.Button(department_window, text="秘书处", width=10, height=2)
button3.grid(row=1, column=0, pady=10, padx=20)
button4 = tk.Button(department_window, text="文体部", width=10, height=2)
button4.grid(row=1, column=1, pady=10, padx=20)
button5 = tk.Button(department_window, text="学习部", width=10, height=2)
button5.grid(row=2, column=0, pady=10, padx=20)
button6 = tk.Button(department_window, text="社会实践部", width=10, height=2)
button6.grid(row=2, column=1, pady=10, padx=20)
button7 = tk.Button(department_window, text="国旗班", width=10, height=2)
button7.grid(row=3, column=0, pady=10, padx=20)
button8 = tk.Button(department_window, text="礼仪队", width=10, height=2)
button8.grid(row=3, column=1, pady=10, padx=20)
# 运行部门主窗口的主循环
department_window.mainloop()
else:
# 登录失败,给出提示信息
messagebox.showerror("错误", "用户名或密码错误!")
# 创建登录按钮
login_button = tk.Button(login_window, text="登录", command=login, width=10, height=2)
login_button.grid(row=2, columnspan=2, pady=10) # 设置Button的位置
# 运行登录窗口的主循环
login_window.mainloop()
|
|