def login_window(): layout = [ [sg.Text('登录')], [sg.Text('用户名'), sg.InputText(key='name')], [sg.Text('密码'), sg.InputText(key='password', password_char='*')], [sg.Button('登录'), sg.Button('取消')] ] window = sg.Window('ATM').Layout(layout) while True: event, values = window.Read() if event in (None, '取消'): break elif event == '登录': name = values['name'] password = values['password'] for user in users: if user.name == name and user.password == password: sg.Popup('登录成功') return user else: sg.Popup('用户名或密码错误') window.Close()

时间: 2024-02-14 08:35:35 浏览: 23
这是一个用 PySimpleGUI 编写的登录窗口,其中包含用户名和密码的输入框,以及登录和取消按钮。当用户点击登录按钮时,程序将会检查用户名和密码是否正确,如果是,则会弹出一个成功登录的窗口,并返回相应的用户对象;如果用户名或密码错误,则会弹出一个警告窗口。如果用户点击取消按钮,则程序会退出登录窗口。
相关问题

def user_login(): # 创建用户登录窗口 user_login_window = tk.Toplevel() #Toplevel 是一个容器控件,用来提供一个单独的对话框 user_login_window.title("用户登录界面") # 创建标签和按钮 label = tk.Label(user_login_window, text="请输入用户名和密码:") label.pack() # 将Label组件添加到窗口中显示 username_label = tk.Label(user_login_window, text="用户名:") username_label.pack() username_entry = tk.Entry(user_login_window) username_entry.pack() # 显示输入框 password_label = tk.Label(user_login_window, text="密码:") password_label.pack() # 将Label组件添加到窗口中显示 password_entry = tk.Entry(user_login_window, show="*") password_entry.pack() # 显示输入框 login_button = tk.Button(user_login_window, text="登录", command=lambda: user_login(username_entry.get(), password_entry.get())) login_button.pack() # 进入消息循环 user_login_window.mainloop()

在你的代码中,`user_login()` 函数是一个无参函数,但是在按钮的命令中,你尝试传递了 `username_entry.get()` 和 `password_entry.get()` 这两个参数。这导致了错误的发生,因为 `user_login()` 函数无法接收这两个参数。 为了解决这个问题,你可以将按钮的命令设置为一个新的函数,然后在这个新函数中调用 `user_login()` 函数,并传递参数。 以下是修改后的代码示例: ```python def user_login(): # 创建用户登录窗口 user_login_window = tk.Toplevel() user_login_window.title("用户登录界面") # 创建标签和按钮 label = tk.Label(user_login_window, text="请输入用户名和密码:") label.pack() username_label = tk.Label(user_login_window, text="用户名:") username_label.pack() username_entry = tk.Entry(user_login_window) username_entry.pack() password_label = tk.Label(user_login_window, text="密码:") password_label.pack() password_entry = tk.Entry(user_login_window, show="*") password_entry.pack() login_button = tk.Button(user_login_window, text="登录", command=login) login_button.pack() # 进入消息循环 user_login_window.mainloop() def login(): # 获取用户名和密码 username = username_entry.get() password = password_entry.get() # 在这里进行用户登录的逻辑处理 # 调用用户登录函数 user_login() ``` 通过将按钮的命令设置为 `login` 函数,我们可以在该函数中获取用户名和密码,并在需要的地方进行用户登录的逻辑处理。请根据你的需求修改 `login` 函数中的代码。

class ExcelApp: def init(self, master): # 创建登录窗口 login_window = tk.Toplevel(master) login_window.title("登录") login_window.geometry("300x150") login_window.resizable(0, 0) # 创建用户名和密码的 Label 和 Entry tk.Label(login_window, text="用户名:").place(x=50, y=30) username_entry = tk.Entry(login_window) username_entry.place(x=110, y=30) tk.Label(login_window, text="密码:").place(x=50, y=70) password_entry = tk.Entry(login_window, show="*") password_entry.place(x=110, y=70) # 创建登录按钮 def login(): username = username_entry.get() password = password_entry.get() if username == "Q21000002" and password == "Q21000002": login_window.destroy() else: tk.messagebox.showwarning(title="登录失败", message="用户名或密码错误!") tk.Button(login_window, text="登录", command=login).place(x=130, y=110) # 创建 Excel App 窗口 if login_window.wait_window() == 0: master.destroy() else: self.master = master master.title("Excel App") # 获取屏幕的宽度和高度 screen_width = master.winfo_screenwidth() screen_height = master.winfo_screenheight() # 将窗口的大小设置为屏幕的大小 master.geometry("%dx%d" % (screen_width, screen_height))修改這個代碼儅運行時不要跳出兩個窗口,沒輸入賬號密碼前只保留一個窗口,儅賬號密碼正確輸入后再將窗口跳出來

您可以尝试将创建 ExcelApp 窗口的代码移动到登录按钮的函数中,并在登录成功后再创建窗口。同时,将登录窗口的销毁放在登录成功的条件语句中,以确保登录窗口仅在登录成功后关闭。 可以参考下面的代码: ``` class ExcelApp: def __init__(self, master): self.master = master self.create_login_window() def create_login_window(self): # 创建登录窗口 self.login_window = tk.Toplevel(self.master) self.login_window.title("登录") self.login_window.geometry("300x150") self.login_window.resizable(0, 0) # 创建用户名和密码的 Label 和 Entry tk.Label(self.login_window, text="用户名:").place(x=50, y=30) self.username_entry = tk.Entry(self.login_window) self.username_entry.place(x=110, y=30) tk.Label(self.login_window, text="密码:").place(x=50, y=70) self.password_entry = tk.Entry(self.login_window, show="*") self.password_entry.place(x=110, y=70) # 创建登录按钮 tk.Button(self.login_window, text="登录", command=self.login).place(x=130, y=110) def login(self): username = self.username_entry.get() password = self.password_entry.get() if username == "Q21000002" and password == "Q21000002": self.login_window.destroy() self.create_excel_app_window() else: tk.messagebox.showwarning(title="登录失败", message="用户名或密码错误!") def create_excel_app_window(self): # 创建 Excel App 窗口 self.master.title("Excel App") # 获取屏幕的宽度和高度 screen_width = self.master.winfo_screenwidth() screen_height = self.master.winfo_screenheight() # 将窗口的大小设置为屏幕的大小 self.master.geometry("%dx%d" % (screen_width, screen_height)) ``` 这样,登录窗口和 Excel App 窗口就可以在同一个窗口中切换了,且只有在登录成功后才会创建 Excel App 窗口。

相关推荐

import tkinter as tk from tkinter import filedialog from common import LayoutCenter class EditForm: def __init__(self, master): self.master = master LayoutCenter(master, "修订评分标准") # 创建滚动条 vsb = tk.Scrollbar(master, orient=tk.VERTICAL) vsb.pack(side="right", fill="y") # 创建文本框并关联滚动条 self.text = tk.Text(self.master, yscrollcommand=vsb.set) self.text.pack(fill="y", expand=True) vsb.config(command=self.text.yview) self.create_menu() self.text.bind("<KeyRelease>", self.update_line_numbers) self.text.tag_configure("line_numbers", justify="right") # 添加行号标记 def update_line_numbers(self,event=None): self.text.delete("line_numbers") for i, line in enumerate(self.text.get("1.0", "end").split("\n")): self.text.insert(f"{i+1}.0", f"{i+1}\n", "line_numbers") def create_menu(self): menu = tk.Menu(self.master) self.master.config(menu=menu) file_menu = tk.Menu(menu) menu.add_cascade(label="File", menu=file_menu) file_menu.add_command(label="Open", command=self.open_file) file_menu.add_command(label="Save", command=self.save_file) file_menu.add_separator() file_menu.add_command(label="Exit", command=self.exit) def open_file(self): file_path = filedialog.askopenfilename() if file_path: with open(file_path, "r") as file: self.text.delete("1.0", "end") self.text.insert("1.0", file.read()) def save_file(self): file_path = filedialog.asksaveasfilename() if file_path: with open(file_path, "w") as file: file.write(self.text.get("1.0", "end")) def exit(self): self.master.destroy() def run(self): self.master.mainloop() root = tk.Tk() my_gui = EditForm(root) root.mainloop()

class MainWindow(QMainWindow): def __init__(self): super().__init__() self.setFixedSize(800, 600) main_layout = QVBoxLayout() central_widget = QWidget() central_widget.setLayout(main_layout) self.setCentralWidget(central_widget) button_layout = QVBoxLayout() button1 = QPushButton('当日员工工资') button1.setFixedSize(200, 50) button1.clicked.connect(self.show_query1_result) button_layout.addStretch() button_layout.addWidget(button1) button_layout.addStretch() layout = QHBoxLayout() layout.addStretch() layout.addLayout(button_layout) layout.addStretch() widget = QWidget() widget.setLayout(layout) self.setCentralWidget(widget) main_layout.addLayout(button_layout) self.query1_window = QueryResultWindow() def show_query1_result(self): db = pymysql.connect(host='39.99.214.172', user='root', password='Solotion.123', db='jj_tset') cursor = db.cursor() db_sql = """ """ cursor.execute(db_sql) result = cursor.fetchall() db.close() if len(result) == 0: QMessageBox.information(self, "提示", "今日无员工工资记录") return self.query1_window.table_widget.setRowCount(0) self.query1_window.table_widget.setColumnCount(len(result[0])) self.query1_window.table_widget.setHorizontalHeaderLabels( ["员工ID", "员工姓名", "日期", "领取鸡爪重量(KG)", "效率(每小时KG)", "出成率", "基础工资", "重量奖励", "当日总工资"]) for row_num, row_data in enumerate(result): self.query1_window.table_widget.insertRow(row_num) for col_num, col_data in enumerate(row_data): self.query1_window.table_widget.setItem(row_num, col_num, QTableWidgetItem(str(col_data))) self.query1_window.show() class QueryResultWindow(QWidget): def __init__(self): super().__init__() self.setFixedSize(800, 600) self.table_widget = QTableWidget() self.table_widget.setEditTriggers(QTableWidget.NoEditTriggers) self.table_widget.setSelectionBehavior(QTableWidget.SelectRows) layout = QVBoxLayout() layout.addWidget(self.table_widget) self.setLayout(layout) if __name__ == '__main__': app = QApplication(sys.argv) loginWindow = LoginWindow() loginWindow.show() sys.exit(app.exec_()))数据展示页面怎么设置筛选器按ID筛选结果并展示

优化这段代码import tkinter as tk class TomatoClock: def init(self, work_time=25, rest_time=5, long_rest_time=15): self.work_time = work_time * 60 self.rest_time = rest_time * 60 self.long_rest_time = long_rest_time * 60 self.count = 0 self.is_working = False self.window = tk.Tk() self.window.title("番茄钟") self.window.geometry("300x200") self.window.config(background='white') self.window.option_add("*Font", ("Arial", 20)) self.label = tk.Label(self.window, text="番茄钟", background='white') self.label.pack(pady=10) self.time_label = tk.Label(self.window, text="", background='white') self.time_label.pack(pady=20) self.start_button = tk.Button(self.window, text="开始", command=self.start_timer, background='white') self.start_button.pack(pady=10) def start_timer(self): self.is_working = not self.is_working if self.is_working: self.count += 1 if self.count % 8 == 0: self.count_down(self.long_rest_time) self.label.config(text="休息时间", foreground='white', background='lightblue') elif self.count % 2 == 0: self.count_down(self.rest_time) self.label.config(text="休息时间", foreground='white', background='lightgreen') else: self.count_down(self.work_time) self.label.config(text="工作时间", foreground='white', background='pink') else: self.label.config(text="番茄钟", foreground='black', background='white') def count_down(self, seconds): if seconds == self.work_time: self.window.config(background='pink') else: self.window.config(background='lightgreen' if seconds == self.rest_time else 'lightblue') if seconds == self.long_rest_time: self.count = 0 minute = seconds // 60 second = seconds % 60 self.time_label.config(text="{:02d}:{:02d}".format(minute, second)) if seconds > 0: self.window.after(1000, self.count_down, seconds - 1) else: self.start_timer() def run(self): self.window.mainloop() if name == 'main': clock = TomatoClock() clock.run()

class MainWindow(QMainWindow): def init(self): super().init() self.setFixedSize(800, 600) main_layout = QVBoxLayout() central_widget = QWidget() central_widget.setLayout(main_layout) self.setCentralWidget(central_widget) button_layout = QVBoxLayout() button1 = QPushButton('当日员工工资') button1.setFixedSize(200, 50) button1.clicked.connect(self.show_query1_result) button_layout.addStretch() button_layout.addWidget(button1) button_layout.addStretch() layout = QHBoxLayout() layout.addStretch() layout.addLayout(button_layout) layout.addStretch() widget = QWidget() widget.setLayout(layout) self.setCentralWidget(widget) main_layout.addLayout(button_layout) self.query1_window = QueryResultWindow() def show_query1_result(self): db = pymysql.connect(host='39.99.214.172', user='root', password='Solotion.123', db='jj_tset') cursor = db.cursor() db_sql = """ """ cursor.execute(db_sql) result = cursor.fetchall() db.close() if len(result) == 0: QMessageBox.information(self, "提示", "今日无员工工资记录") return self.query1_window.table_widget.setRowCount(0) self.query1_window.table_widget.setColumnCount(len(result[0])) self.query1_window.table_widget.setHorizontalHeaderLabels( ["员工ID", "员工姓名", "日期", "领取鸡爪重量(KG)", "效率(每小时KG)", "出成率", "基础工资", "重量奖励", "当日总工资"]) for row_num, row_data in enumerate(result): self.query1_window.table_widget.insertRow(row_num) for col_num, col_data in enumerate(row_data): self.query1_window.table_widget.setItem(row_num, col_num, QTableWidgetItem(str(col_data))) self.query1_window.show() class QueryResultWindow(QWidget): def init(self): super().init() self.setFixedSize(800, 600) self.table_widget = QTableWidget() self.table_widget.setEditTriggers(QTableWidget.NoEditTriggers) self.table_widget.setSelectionBehavior(QTableWidget.SelectRows) layout = QVBoxLayout() layout.addWidget(self.table_widget) self.setLayout(layout) if name == 'main': app = QApplication(sys.argv) loginWindow = LoginWindow() loginWindow.show() sys.exit(app.exec_()))数据展示页面怎么设置筛选器按ID筛选结果并展示的整体代码

最新推荐

recommend-type

3796 i-FRAME 安装、操作和维护手册

3796 i-FRAME 安装、操作和维护手册
recommend-type

我的visio画图 资源备用

我的visio画图
recommend-type

RTL8188FU-Linux-v5.7.4.2-36687.20200602.tar(20765).gz

REALTEK 8188FTV 8188eus 8188etv linux驱动程序稳定版本, 支持AP,STA 以及AP+STA 共存模式。 稳定支持linux4.0以上内核。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

:YOLOv1目标检测算法:实时目标检测的先驱,开启计算机视觉新篇章

![:YOLOv1目标检测算法:实时目标检测的先驱,开启计算机视觉新篇章](https://img-blog.csdnimg.cn/img_convert/69b98e1a619b1bb3c59cf98f4e397cd2.png) # 1. 目标检测算法概述 目标检测算法是一种计算机视觉技术,用于识别和定位图像或视频中的对象。它在各种应用中至关重要,例如自动驾驶、视频监控和医疗诊断。 目标检测算法通常分为两类:两阶段算法和单阶段算法。两阶段算法,如 R-CNN 和 Fast R-CNN,首先生成候选区域,然后对每个区域进行分类和边界框回归。单阶段算法,如 YOLO 和 SSD,一次性执行检
recommend-type

ActionContext.getContext().get()代码含义

ActionContext.getContext().get() 是从当前请求的上下文对象中获取指定的属性值的代码。在ActionContext.getContext()方法的返回值上,调用get()方法可以获取当前请求中指定属性的值。 具体来说,ActionContext是Struts2框架中的一个类,它封装了当前请求的上下文信息。在这个上下文对象中,可以存储一些请求相关的属性值,比如请求参数、会话信息、请求头、应用程序上下文等等。调用ActionContext.getContext()方法可以获取当前请求的上下文对象,而调用get()方法可以获取指定属性的值。 例如,可以使用 Acti
recommend-type

c++校园超市商品信息管理系统课程设计说明书(含源代码) (2).pdf

校园超市商品信息管理系统课程设计旨在帮助学生深入理解程序设计的基础知识,同时锻炼他们的实际操作能力。通过设计和实现一个校园超市商品信息管理系统,学生掌握了如何利用计算机科学与技术知识解决实际问题的能力。在课程设计过程中,学生需要对超市商品和销售员的关系进行有效管理,使系统功能更全面、实用,从而提高用户体验和便利性。 学生在课程设计过程中展现了积极的学习态度和纪律,没有缺勤情况,演示过程流畅且作品具有很强的使用价值。设计报告完整详细,展现了对问题的深入思考和解决能力。在答辩环节中,学生能够自信地回答问题,展示出扎实的专业知识和逻辑思维能力。教师对学生的表现予以肯定,认为学生在课程设计中表现出色,值得称赞。 整个课程设计过程包括平时成绩、报告成绩和演示与答辩成绩三个部分,其中平时表现占比20%,报告成绩占比40%,演示与答辩成绩占比40%。通过这三个部分的综合评定,最终为学生总成绩提供参考。总评分以百分制计算,全面评估学生在课程设计中的各项表现,最终为学生提供综合评价和反馈意见。 通过校园超市商品信息管理系统课程设计,学生不仅提升了对程序设计基础知识的理解与应用能力,同时也增强了团队协作和沟通能力。这一过程旨在培养学生综合运用技术解决问题的能力,为其未来的专业发展打下坚实基础。学生在进行校园超市商品信息管理系统课程设计过程中,不仅获得了理论知识的提升,同时也锻炼了实践能力和创新思维,为其未来的职业发展奠定了坚实基础。 校园超市商品信息管理系统课程设计的目的在于促进学生对程序设计基础知识的深入理解与掌握,同时培养学生解决实际问题的能力。通过对系统功能和用户需求的全面考量,学生设计了一个实用、高效的校园超市商品信息管理系统,为用户提供了更便捷、更高效的管理和使用体验。 综上所述,校园超市商品信息管理系统课程设计是一项旨在提升学生综合能力和实践技能的重要教学活动。通过此次设计,学生不仅深化了对程序设计基础知识的理解,还培养了解决实际问题的能力和团队合作精神。这一过程将为学生未来的专业发展提供坚实基础,使其在实际工作中能够胜任更多挑战。
recommend-type

"互动学习:行动中的多样性与论文攻读经历"

多样性她- 事实上SCI NCES你的时间表ECOLEDO C Tora SC和NCESPOUR l’Ingén学习互动,互动学习以行动为中心的强化学习学会互动,互动学习,以行动为中心的强化学习计算机科学博士论文于2021年9月28日在Villeneuve d'Asq公开支持马修·瑟林评审团主席法布里斯·勒菲弗尔阿维尼翁大学教授论文指导奥利维尔·皮耶昆谷歌研究教授:智囊团论文联合主任菲利普·普雷教授,大学。里尔/CRISTAL/因里亚报告员奥利维耶·西格德索邦大学报告员卢多维奇·德诺耶教授,Facebook /索邦大学审查员越南圣迈IMT Atlantic高级讲师邀请弗洛里安·斯特鲁布博士,Deepmind对于那些及时看到自己错误的人...3谢谢你首先,我要感谢我的两位博士生导师Olivier和Philippe。奥利维尔,"站在巨人的肩膀上"这句话对你来说完全有意义了。从科学上讲,你知道在这篇论文的(许多)错误中,你是我可以依
recommend-type

:YOLO目标检测算法的挑战与机遇:数据质量、计算资源与算法优化,探索未来发展方向

![:YOLO目标检测算法的挑战与机遇:数据质量、计算资源与算法优化,探索未来发展方向](https://img-blog.csdnimg.cn/7e3d12895feb4651b9748135c91e0f1a.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA5rKJ6YaJ77yM5LqO6aOO5Lit,size_20,color_FFFFFF,t_70,g_se,x_16) # 1. YOLO目标检测算法简介 YOLO(You Only Look Once)是一种
recommend-type

设计一个算法,输出在顺序表{3,6,2,10,1,8,5,7,4,9}中采用顺序方法查找关键字5的过程。

好的,我来回答你的问题。 在顺序表中查找关键字5的过程如下: 1. 从顺序表的第一个元素(即3)开始,逐个比较元素的值与目标值5是否相等。 2. 发现第一个元素3不等于目标值5,继续向下查找。 3. 查找到第三个元素2时,发现该元素也不等于目标值5,继续向下查找。 4. 查找到第四个元素10时,发现该元素也不等于目标值5,继续向下查找。 5. 查找到第五个元素1时,发现该元素也不等于目标值5,继续向下查找。 6. 查找到第六个元素8时,发现该元素也不等于目标值5,继续向下查找。 7. 查找到第七个元素5时,发现该元素等于目标值5,查找成功。 因此,顺序表中采用顺序方法查找关键