diff --git a/b1.png b/b1.png new file mode 100644 index 0000000..30d5a0c Binary files /dev/null and b/b1.png differ diff --git a/b2.png b/b2.png new file mode 100644 index 0000000..937c943 Binary files /dev/null and b/b2.png differ diff --git a/b3o.png b/b3o.png new file mode 100644 index 0000000..9955ca8 Binary files /dev/null and b/b3o.png differ diff --git a/demo2.py b/demo2.py new file mode 100644 index 0000000..924a8db --- /dev/null +++ b/demo2.py @@ -0,0 +1,98 @@ +import sys +from PyQt5.QtWidgets import QApplication, QWidget, QLineEdit, QPushButton, QVBoxLayout, QHBoxLayout, QLabel +from PyQt5.QtCore import Qt +from PyQt5.QtGui import QPixmap, QPainter + +class MyApp(QWidget): + def __init__(self): + super().__init__() + self.initUI() + + def initUI(self): + # 加载背景图片 + self.background = QPixmap('hnu.jpg') + + # 创建一个垂直布局 + mainLayout = QVBoxLayout() + + # 创建三个文本框并设置占位符 + self.nameEdit = QLineEdit() + self.pwdEdit = QLineEdit() + self.urlEdit = QLineEdit() + self.nameEdit.setPlaceholderText('Name') + self.pwdEdit.setPlaceholderText('Password') + self.urlEdit.setPlaceholderText('URL') + + # 创建一个按钮并连接信号 + btn = QPushButton('提交') + btn.clicked.connect(self.onSubmit) + + # 对于每个输入框,创建一个水平布局以保持居中 + for label_text, edit_widget in [("用户名", self.nameEdit), + ("密码", self.pwdEdit), + ("实训网址", self.urlEdit)]: + hbox = QHBoxLayout() + hbox.addStretch() + vbox_inner = QVBoxLayout() + vbox_inner.addWidget(QLabel(label_text)) + vbox_inner.addWidget(edit_widget) + hbox.addLayout(vbox_inner) + hbox.addStretch() + mainLayout.addLayout(hbox) + + # 添加按钮到布局 + mainLayout.addWidget(btn, 0, Qt.AlignCenter) + + # 设置窗口的布局 + self.setLayout(mainLayout) + self.setWindowTitle('') + self.setGeometry(300, 300, 400, 300) + self.centerWindow() + + # 应用样式 + self.applyStyles() + + def paintEvent(self, event): + painter = QPainter(self) + + # 计算背景图片绘制的起始坐标,使其位于窗口中心 + bgWidth = self.background.width() + bgHeight = self.background.height() + startX = (self.width() - bgWidth) // 2 + startY = (self.height() - bgHeight) // 2 + + painter.drawPixmap(startX, startY, self.background) + + def centerWindow(self): + qr = self.frameGeometry() + cp = QApplication.desktop().availableGeometry().center() + qr.moveCenter(cp) + self.move(qr.topLeft()) + + def applyStyles(self): + self.setStyleSheet(""" + QLineEdit { + border: 1px solid gray; + border-radius: 10px; + padding: 5px; + background: transparent; + } + QLineEdit:focus { + border: 1px solid LightSeaGreen; + } + """) + + def onSubmit(self): + name = self.nameEdit.text() + pwd = self.pwdEdit.text() + url = self.urlEdit.text() + print(f"Name: {name}, Password: {pwd}, URL: {url}") + + # 关闭窗口 + self.close() + +if __name__ == '__main__': + app = QApplication(sys.argv) + ex = MyApp() + ex.show() + sys.exit(app.exec_()) diff --git a/hnu.jpg b/hnu.jpg new file mode 100644 index 0000000..794fc61 Binary files /dev/null and b/hnu.jpg differ diff --git a/login_ui.py b/login_ui.py new file mode 100644 index 0000000..5a5508a --- /dev/null +++ b/login_ui.py @@ -0,0 +1,116 @@ +import sys +from PyQt5.QtWidgets import QApplication, QWidget, QLineEdit, QPushButton, QVBoxLayout, QHBoxLayout, QLabel +from PyQt5.QtCore import Qt +from PyQt5.QtGui import QPixmap, QPainter +import os +class MyApp(QWidget): + def __init__(self): + super().__init__() + self.initUI() + + def initUI(self): + # 加载背景图片 + self.background = QPixmap('b3o.png') + # 创建一个垂直布局 + mainLayout = QVBoxLayout() + + # 创建三个文本框并设置占位符 + self.nameEdit = QLineEdit() + self.pwdEdit = QLineEdit() + self.urlEdit = QLineEdit() + # self.nameEdit.setPlaceholderText('Name') + # self.pwdEdit.setPlaceholderText('Password') + # self.urlEdit.setPlaceholderText('URL') + + # 创建一个按钮并连接信号 + btn = QPushButton('提交') + btn.clicked.connect(self.onSubmit) + + self.setWindowTitle('头歌助手登录') + # 对于每个输入框,创建一个水平布局以保持居中 + for label_text, edit_widget in [("用户名", self.nameEdit), + ("密 码", self.pwdEdit), + ("实训网址", self.urlEdit)]: + hbox = QHBoxLayout() #创建一个水平布局 + hbox.addStretch() #添加一个伸缩因子,使得文本框和按钮位于窗口中心 + vbox_inner = QVBoxLayout() #创建一个垂直布局 + vbox_inner.addWidget(QLabel(label_text)) #添加一个标签 + vbox_inner.addWidget(edit_widget) #添加一个文本框 + hbox.addLayout(vbox_inner) #将垂直布局添加到水平布局中 + hbox.addStretch() #添加一个伸缩因子,使得文本框和按钮位于窗口中心 + mainLayout.addLayout(hbox) #将水平布局添加到垂直布局中 + + # 添加按钮到布局 + mainLayout.addWidget(btn, 0, Qt.AlignCenter) + + # 设置窗口的布局 + self.setLayout(mainLayout) + self.setWindowTitle('') + self.setGeometry(300, 300, 650,550) # 设置窗口大小,其中300,300为窗口左上角坐标,1000,600为窗口大小 + self.centerWindow() + + # 应用样式 + self.applyStyles() + self.show() + + def paintEvent(self, event): + painter = QPainter(self) + painter.drawPixmap(self.rect(), self.background) + + def centerWindow(self): + qr = self.frameGeometry() + cp = QApplication.desktop().availableGeometry().center() + qr.moveCenter(cp) + self.move(qr.topLeft()) + + def applyStyles(self): + # css 用于设置窗口样式 + self.setStyleSheet(""" + QLineEdit { + border: 1px solid gray; + border-radius: 10px; + padding: 5px; + background: rgba(255, 255, 255, 100); + } + QLineEdit:focus { + border: 1px solid black; + } + QLabel { + color: black; + font-size: 23pt; + margin-top: 50px; /* 顶部外边距 */ + margin-left: 20px; /* 左侧外边距 */ + } + QLineEdit { + border: 1px solid gray; + border-radius: 10px; + padding: 5px; + background: rgba(255, 255, 255, 100); + color: black; /* 设置输入文本颜色为黑色 */ + width: 300px; /* 设置输入框宽度 */ + height: 30px; /* 设置输入框高度 */ + } + QPushButton { + border: 1px solid gray; + border-radius: 10px; + padding: 5px; + background: rgba(255, 255, 255, 100); + color: black; /* 设置按钮文本颜色为黑色 */ + width: 100px; /* 设置按钮宽度 */ + height: 27px; /* 设置按钮高度 */ + } + """) + + def onSubmit(self): + name = self.nameEdit.text() + pwd = self.pwdEdit.text() + url = self.urlEdit.text() + print(f"Name: {name}, Password: {pwd}, URL: {url}") + + # 关闭窗口 + self.close() +os.system('python3 show_welcome.py') +app = QApplication(sys.argv) +ex = MyApp() +ex.show() +sys.exit(app.exec_()) \ No newline at end of file diff --git a/main.py b/main.py index d54365a..886f5bd 100644 --- a/main.py +++ b/main.py @@ -4,4 +4,12 @@ 2、get_params.py获取参数 3、get_answer.py获取答案 4、cloud.py将json文件存入云端 -''' \ No newline at end of file +''' + +# 生成图形化界面,引导用户登陆并输入实训网址 +# 调用get_params.py获取参数,这一步同时隐含了云端获取答案的过程 +# 如果云端答案不存在,则调用get_answer.py获取答案,并展示给用户 +# 用户verif选项确认后,调用cloud.py将json文件存入云端 + + +import login_ui \ No newline at end of file diff --git a/show_welcome.py b/show_welcome.py new file mode 100644 index 0000000..d232daa --- /dev/null +++ b/show_welcome.py @@ -0,0 +1,39 @@ +import sys +from PyQt5.QtWidgets import QApplication, QLabel, QWidget +from PyQt5.QtGui import QPixmap +from PyQt5.QtCore import QTimer, Qt + +class ImageWindow(QWidget): + def __init__(self, image_path): + super().__init__() + self.initUI(image_path) + + def initUI(self, image_path): + self.setWindowFlags(Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint) + self.setAttribute(Qt.WA_TranslucentBackground) + + label = QLabel(self) + pixmap = QPixmap(image_path) + + # 缩放图片到期望的大小 + scaled_pixmap = pixmap.scaled(700, 400, Qt.KeepAspectRatio) # 设置图片大小为400x300,并保持纵横比 + label.setPixmap(scaled_pixmap) + self.resize(scaled_pixmap.width(), scaled_pixmap.height()) + + # 居中显示窗口 + qr = self.frameGeometry() + cp = QApplication.desktop().availableGeometry().center() + qr.moveCenter(cp) + self.move(qr.topLeft()) + + QTimer.singleShot(3000, self.close) + +def show(): + app = QApplication(sys.argv) + ex = ImageWindow('b2.png') + ex.show() + sys.exit(app.exec_()) + +if __name__ == '__main__': + show() +