【发布时间】:2018-12-28 01:26:36
【问题描述】:
我正在尝试在 QMainWindow 类中显示图片:
from PyQt5.QtWidgets import QLabel, QMainWindow, QApplication
from PyQt5.QtGui import QPixmap
import sys
class Menu(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("Title")
label = QLabel(self)
pixmap = QPixmap('capture.png')
label.setPixmap(pixmap)
self.resize(pixmap.width(), pixmap.height())
self.show()
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = Menu()
sys.exit(app.exec_())
但它不显示图像,只是打开窗口。我坚持使用QMainWindow 课程,因为我正在尝试编写类似绘画应用程序的东西,这样我就可以编写菜单,并且可以在图片上写字。
任何建议将不胜感激。
谢谢。
【问题讨论】:
-
与您的问题无关,但您使用的是什么版本的python?
-
Python 3.6.5 蟒蛇
-
您是否尝试过使用 jpg 图片?
-
您误用了
QMainWindow。看QMainWindow::setCentralWidget。 -
@TheCrystalShip 啊,我明白了,你是在 Unix 系统还是 DOS 下工作?
标签: python python-3.x qt pyqt5 qmainwindow