def initUI(self): # 连接数据库,获取员工信息 conn = pymysql.connect(host='39.99.214.172', user='root', password='Solotion.123', database='jj_tset') cursor = conn.cursor() cursor.execute("SELECT * FROM employee_table WHERE user_id='%s'" % self.user_id) result = cursor.fetchone() conn.close() # 创建用于显示员工信息的控件 info_label = QLabel("员工信息", self) info_label.move(100, 50) name_label = QLabel("员工ID:" + result[0], self) name_label.move(70, 100) age_label = QLabel("姓名:" + str(result[1]), self) age_label.move(70, 150) name_label = QLabel("性别:" + result[2], self) name_label.move(70, 200) age_label = QLabel("身份证:" + str(result[3]), self) age_label.move(70, 250) name_label = QLabel("电话:" + result[4], self) name_label.move(70, 300) # 创建返回按钮 back_button = QPushButton('返回', self) back_button.setGeometry(600, 400, 100, 50) back_button.clicked.connect(self.backToLoginWindow) # 设置窗口大小和标题 self.setFixedSize(800, 500) self.setWindowTitle('员工信息')怎么美化
时间: 2023-11-27 15:06:18 浏览: 33
可以通过设置控件的样式表来美化界面。以下是一个示例代码,可以将控件的背景色和字体颜色等进行设置:
```
# 设置info_label的样式
info_label.setStyleSheet("font-size: 24px; color: #333; background-color: #eee; border-radius: 10px;")
# 设置name_label的样式
name_label.setStyleSheet("font-size: 18px; color: #555;")
# 设置age_label的样式
age_label.setStyleSheet("font-size: 18px; color: #555;")
# 设置back_button的样式
back_button.setStyleSheet("font-size: 16px; color: #fff; background-color: #333; border-radius: 5px;")
```
你可以根据自己的需求,调整样式表中的属性值。同时,也可以使用Qt Designer进行可视化设计,更加方便地进行界面美化。
相关问题
class EmployeeInfoWindow(QWidget): def init(self, user_id): super().init() self.user_id = user_id self.initUI() def initUI(self): # 连接数据库,获取员工信息 conn = pymysql.connect(host='39.99.214.172', user='root', password='Solotion.123', database='jj_tset') cursor = conn.cursor() cursor.execute("SELECT * FROM employee_table WHERE user_id='%s'" % self.user_id) result = cursor.fetchone() conn.close() # 创建用于显示员工信息的控件 info_label = QLabel("员工信息", self) info_label.move(100, 100) name_label = QLabel("姓名:" + result[1], self) name_label.move(100, 150) age_label = QLabel("年龄:" + str(result[2]), self) age_label.move(100, 200) # TODO: 创建其他员工信息控件 # 设置窗口大小和标题 self.setFixedSize(800, 500) self.setWindowTitle('员工信息') class LoginWindow(QWidget): def init(self): super().init() self.initUI() def initUI(self): self.setFixedSize(800, 500) self.setWindowTitle('鸡爪称重系统') # 创建一个按钮 button = QPushButton('开始称重', self) button.move(100, 100) button.setGeometry(300, 200, 200, 50) button.clicked.connect(self.showInputDialog) def showInputDialog(self): # 创建一个输入框,获取员工ID text, okPressed = QInputDialog.getText(self, "输入员工ID", "输入员工ID:") if okPressed and text != '': # 连接数据库,检查员工ID是否存在 conn = pymysql.connect(host='39.99.214.172', user='root', password='Solotion.123', database='jj_tset') cursor = conn.cursor() cursor.execute("SELECT * FROM employee_table WHERE user_id='%s'" % text) result = cursor.fetchone() conn.close() if result: # 员工ID存在,跳转到下一个界面,显示员工信息 print('输入的ID是:', text) employee_info_window = EmployeeInfoWindow(text) employee_info_window.show() self.hide() else: # 员工ID不存在,弹出提示框,提示重新输入 QMessageBox.warning(self, '错误', '员工ID不存在,请重新输入!') if name == 'main': app = QApplication(sys.argv) loginWindow = LoginWindow() loginWindow.show() sys.exit(app.exec_())怎么更改为跳转界面
可以使用QStackedWidget来实现界面跳转,具体实现步骤如下:
1. 在LoginWindow类中添加一个QStackedWidget控件,用于显示不同的界面。
2. 在showInputDialog方法中,如果员工ID存在,就将QStackedWidget控件切换到EmployeeInfoWindow界面。
3. 在EmployeeInfoWindow中添加返回按钮,用于返回到LoginWindow界面。
下面是代码示例:
```
class EmployeeInfoWindow(QWidget):
def __init__(self, user_id, stacked_widget):
super().__init__()
self.user_id = user_id
self.stacked_widget = stacked_widget
self.initUI()
def initUI(self):
# 连接数据库,获取员工信息
conn = pymysql.connect(host='39.99.214.172', user='root', password='Solotion.123', database='jj_tset')
cursor = conn.cursor()
cursor.execute("SELECT * FROM employee_table WHERE user_id='%s'" % self.user_id)
result = cursor.fetchone()
conn.close()
# 创建用于显示员工信息的控件
info_label = QLabel("员工信息", self)
info_label.move(100, 100)
name_label = QLabel("姓名:" + result[1], self)
name_label.move(100, 150)
age_label = QLabel("年龄:" + str(result[2]), self)
age_label.move(100, 200)
# 创建返回按钮
back_button = QPushButton('返回', self)
back_button.setGeometry(600, 400, 100, 50)
back_button.clicked.connect(self.backToLoginWindow)
# 设置窗口大小和标题
self.setFixedSize(800, 500)
self.setWindowTitle('员工信息')
def backToLoginWindow(self):
self.stacked_widget.setCurrentIndex(0)
class LoginWindow(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.setFixedSize(800, 500)
self.setWindowTitle('鸡爪称重系统')
# 创建一个QStackedWidget控件
self.stacked_widget = QStackedWidget(self)
self.stacked_widget.setGeometry(0, 0, 800, 500)
# 创建Login界面
login_widget = QWidget()
self.stacked_widget.addWidget(login_widget)
# 在Login界面上创建一个按钮
button = QPushButton('开始称重', login_widget)
button.move(100, 100)
button.setGeometry(300, 200, 200, 50)
button.clicked.connect(self.showInputDialog)
def showInputDialog(self):
# 创建一个输入框,获取员工ID
text, okPressed = QInputDialog.getText(self, "输入员工ID", "输入员工ID:")
if okPressed and text != '':
# 连接数据库,检查员工ID是否存在
conn = pymysql.connect(host='39.99.214.172', user='root', password='Solotion.123', database='jj_tset')
cursor = conn.cursor()
cursor.execute("SELECT * FROM employee_table WHERE user_id='%s'" % text)
result = cursor.fetchone()
conn.close()
if result:
# 员工ID存在,切换到EmployeeInfoWindow界面,显示员工信息
employee_info_window = EmployeeInfoWindow(text, self.stacked_widget)
self.stacked_widget.addWidget(employee_info_window)
self.stacked_widget.setCurrentIndex(1)
else:
# 员工ID不存在,弹出提示框,提示重新输入
QMessageBox.warning(self, '错误', '员工ID不存在,请重新输入!')
if __name__ == '__main__':
app = QApplication(sys.argv)
loginWindow = LoginWindow()
loginWindow.show()
sys.exit(app.exec_())
```
class LoginWindow(QWidget): def __init__(self): super().__init__() self.initUI() def initUI(self): self.setFixedSize(800, 500) self.setWindowTitle('鸡爪称重系统') # 创建一个按钮 button = QPushButton('开始称重', self) button.move(100, 100) button.setGeometry(300, 200, 200, 50) button.clicked.connect(self.showInputDialog) def showInputDialog(self): # 创建一个输入框,获取员工ID text, okPressed = QInputDialog.getText(self, "输入员工ID", "输入员工ID:") if okPressed and text != '': # 连接数据库,检查员工ID是否存在 conn = pymysql.connect(host='39.99.214.172', user='root', password='Solotion.123', database='jj_tset') cursor = conn.cursor() cursor.execute("SELECT * FROM employee_table WHERE user_id='%s'" % text) result = cursor.fetchone() print(result) if result: # 员工ID存在,跳转到下一个界面 print('输入的ID是:', text) # TODO: 跳转到下一个界面 else: # 员工ID不存在,弹出提示框,提示重新输入 QMessageBox.warning(self, '错误', '员工ID不存在,请重新输入!') if __name__ == '__main__': app = QApplication(sys.argv) loginWindow = LoginWindow() loginWindow.show() sys.exit(app.exec_())如果ID存在,跳转下个界面,显示员工信息
在showInputDialog方法中,如果员工ID存在,可以通过以下步骤跳转到下一个界面并显示员工信息:
1. 创建一个新的界面类(例如EmployeeInfoWindow),继承自QWidget类。
2. 在EmployeeInfoWindow类的构造函数中,传入员工ID作为参数,并连接数据库,获取该员工的信息。
3. 在EmployeeInfoWindow类中,创建显示员工信息的控件(例如QLabel或QTableView等),并将员工信息显示在这些控件上。
4. 在showInputDialog方法中,如果员工ID存在,实例化EmployeeInfoWindow类,并传入员工ID参数,然后调用show方法显示该界面。
下面是修改后的代码示例:
```
class EmployeeInfoWindow(QWidget):
def __init__(self, user_id):
super().__init__()
self.user_id = user_id
self.initUI()
def initUI(self):
# 连接数据库,获取员工信息
conn = pymysql.connect(host='39.99.214.172', user='root', password='Solotion.123', database='jj_tset')
cursor = conn.cursor()
cursor.execute("SELECT * FROM employee_table WHERE user_id='%s'" % self.user_id)
result = cursor.fetchone()
conn.close()
# 创建用于显示员工信息的控件
info_label = QLabel("员工信息", self)
info_label.move(100, 100)
name_label = QLabel("姓名:" + result[1], self)
name_label.move(100, 150)
age_label = QLabel("年龄:" + str(result[2]), self)
age_label.move(100, 200)
# TODO: 创建其他员工信息控件
# 设置窗口大小和标题
self.setFixedSize(800, 500)
self.setWindowTitle('员工信息')
class LoginWindow(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.setFixedSize(800, 500)
self.setWindowTitle('鸡爪称重系统')
# 创建一个按钮
button = QPushButton('开始称重', self)
button.move(100, 100)
button.setGeometry(300, 200, 200, 50)
button.clicked.connect(self.showInputDialog)
def showInputDialog(self):
# 创建一个输入框,获取员工ID
text, okPressed = QInputDialog.getText(self, "输入员工ID", "输入员工ID:")
if okPressed and text != '':
# 连接数据库,检查员工ID是否存在
conn = pymysql.connect(host='39.99.214.172', user='root', password='Solotion.123', database='jj_tset')
cursor = conn.cursor()
cursor.execute("SELECT * FROM employee_table WHERE user_id='%s'" % text)
result = cursor.fetchone()
conn.close()
if result:
# 员工ID存在,跳转到下一个界面,显示员工信息
print('输入的ID是:', text)
employee_info_window = EmployeeInfoWindow(text)
employee_info_window.show()
else:
# 员工ID不存在,弹出提示框,提示重新输入
QMessageBox.warning(self, '错误', '员工ID不存在,请重新输入!')
if __name__ == '__main__':
app = QApplication(sys.argv)
loginWindow = LoginWindow()
loginWindow.show()
sys.exit(app.exec_())
```
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![java](https://img-home.csdnimg.cn/images/20210720083646.png)