使用 python 库 PyQt5 更改主界面的颜色
Change the color of the main interface with the python library PyQt5
如果是Qwidget类型,下面的代码改变了界面的颜色。如果是Qmainwidow,我可以更改界面颜色吗?感谢帮助
import sys
from PyQt5.QtWidgets import (QApplication, QMainWindow, QWidget, QVBoxLayout)
# class Wind(QMainWindow): # this what i need
class Wind(QWidget):
def __init__(self): #__init__ method
super(Wind, self).__init__()
self.scaleFactor = 0.0
self.widget = QWidget(self)
layout = QVBoxLayout(self)
layout.addWidget(self.widget)
self.widget.setStyleSheet("""
.QWidget {
background-color: rgb(0, 200, 0);
}
""")
self.setWindowTitle("first-window")
self.resize(500, 400)
if __name__ == '__main__':
app = QApplication(sys.argv)
imageViewer = Wind()
imageViewer.show()
sys.exit(app.exec_())
这似乎是正确显示的代码。
from PyQt5.QtWidgets import (QApplication, QMainWindow, QWidget, QVBoxLayout)
import sys
#class Wind(QWidget): #Class Name
class Wind(QMainWindow): # Class Name
def __init__(self): #__init__ method
super(Wind, self).__init__()
self.scaleFactor = 0.0
self.widget = QWidget(self)
layout = QVBoxLayout(self)
layout.addWidget(self.widget)
self.widget.setStyleSheet("""
.QWidget {
background-color: rgb(0, 200, 0);
}
""")
self.setWindowTitle("first-window")
self.resize(500, 400)
if __name__ == '__main__':
app = QApplication(sys.argv)
imageViewer = Wind()
imageViewer.show()
sys.exit(app.exec_())
如果是Qwidget类型,下面的代码改变了界面的颜色。如果是Qmainwidow,我可以更改界面颜色吗?感谢帮助
import sys
from PyQt5.QtWidgets import (QApplication, QMainWindow, QWidget, QVBoxLayout)
# class Wind(QMainWindow): # this what i need
class Wind(QWidget):
def __init__(self): #__init__ method
super(Wind, self).__init__()
self.scaleFactor = 0.0
self.widget = QWidget(self)
layout = QVBoxLayout(self)
layout.addWidget(self.widget)
self.widget.setStyleSheet("""
.QWidget {
background-color: rgb(0, 200, 0);
}
""")
self.setWindowTitle("first-window")
self.resize(500, 400)
if __name__ == '__main__':
app = QApplication(sys.argv)
imageViewer = Wind()
imageViewer.show()
sys.exit(app.exec_())
这似乎是正确显示的代码。
from PyQt5.QtWidgets import (QApplication, QMainWindow, QWidget, QVBoxLayout)
import sys
#class Wind(QWidget): #Class Name
class Wind(QMainWindow): # Class Name
def __init__(self): #__init__ method
super(Wind, self).__init__()
self.scaleFactor = 0.0
self.widget = QWidget(self)
layout = QVBoxLayout(self)
layout.addWidget(self.widget)
self.widget.setStyleSheet("""
.QWidget {
background-color: rgb(0, 200, 0);
}
""")
self.setWindowTitle("first-window")
self.resize(500, 400)
if __name__ == '__main__':
app = QApplication(sys.argv)
imageViewer = Wind()
imageViewer.show()
sys.exit(app.exec_())