1 回答
TA贡献1829条经验 获得超7个赞
Alec 回答了这个问题,但如果您仍然不清楚,这里是更正后的代码。
import sys
from PyQt5.QtWidgets import QMainWindow, QLabel, QPushButton, QMessageBox, QApplication
from PyQt5.QtCore import pyqtSignal, pyqtSlot
from PyQt5.QtGui import QIcon, QFont
class MainWindow(QMainWindow):
switch_window=pyqtSignal(str)
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
#Initialize
self.setGeometry(1000, 300, 1200, 800)
self.setWindowTitle('Sensorlyze')
self.setWindowIcon(QIcon('biosensor.jpg'))
icon = QIcon('biosensor.jpg')
# Add Text
l1= QLabel("Welcome to SensorLyze",self)
l1.move(25, 350)
# l1.setWordWrap(True)
l1.setFont(QFont('Calibri',15))
l1.adjustSize()
l2 = QLabel("A software to simply sensor analytics", self)
l2.move(25, 400)
l2.setFont(QFont('Calibri', 10))
l2.adjustSize()
#Add Buttons
button1 = QPushButton('Start',self)
button1.resize(button1.sizeHint())
button1.clicked.connect(self.start_clicked)
button1.move(60, 450)
button2 = QPushButton('Exit', self)
button2.resize(button2.sizeHint())
button2.clicked.connect(self.exit_clicked)
button2.move(240, 450)
def start_clicked(self):
self.window = QMainWindow()
self.window.setGeometry(300, 500, 500, 500)
self.window.setWindowTitle('Hello')
self.window.show()
# win.hide()
def exit_clicked(self):
msgBox = QMessageBox()
msgBox.setIcon(QMessageBox.Information)
msgBox.setText("Are you sure you want to exit?")
msgBox.setWindowTitle("Exit Sensorlyze")
msgBox.setStandardButtons(QMessageBox.Ok | QMessageBox.Cancel)
msgBox.buttonClicked.connect(self.msgButtonClick)
returnValue = msgBox.exec()
if returnValue == QMessageBox.Ok:
exit()
def msgButtonClick(self, i):
print("Buttonclickedis:", i.text())
stylesheet = """
QMainWindow {
background-image: url("C:/Users/admin/Desktop/Sensorlyze/biosensor.jpg");
background-repeat: no-repeat;
background-position: center;
}
"""
# def switch(self):
# self.switch_window.emit(self.line_edit.text())
def main():
app = QApplication(sys.argv)
app.setStyleSheet(stylesheet) # <---
win=MainWindow()
win.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
添加回答
举报