pyQt5在同一窗口中添加多个图像

我打算用pyQt5创建一个音乐播放器,这对像我这样的初学者来说有点困难。回到我的问题,我想添加7张不同的图像:第一个是专辑封面,其余的则是图像具有类似歌曲标题,专辑,艺术家等的图标的作用。

但是当我尝试这段代码

pic = QtGui.QLabel(self)
pic.setPixmap(QtGui.QPixmap("Q107.png"))
pic.resize(250,80)
pic.move(20,90)
pic.show()


pic1 = QtGui.QLabel(self)
pic1.setPixmap(QtGui.QPixmap("Q307.png"))
pic1.resize(250,80)
pic1.move(20,90)
pic1.show()

程序仅显示1张图像-第一张图像

对不起,我的英语不好

感谢您阅读

lxmforyou 回答:pyQt5在同一窗口中添加多个图像

两个图像都位于相同的位置(20,90),因此一个图像隐藏在另一个图像之下。更改pic1的位置后,它将显示两个图像。

import sys
from PyQt5.QtWidgets import QApplication,QWidget,QLabel
from PyQt5.QtGui import QPixmap

class App(QWidget):
    def __init__(self):
        super().__init__()

        pic = QLabel(self)
        pic.setPixmap(QPixmap("Q107.png"))
        pic.resize(250,80)
        pic.move(20,90)
        pic.show()

        pic1 = QLabel(self)
        pic1.setPixmap(QPixmap("Q307.png"))
        pic1.resize(250,80)
        pic1.move(20,190)
        pic1.show()

        self.show()

if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = App()
    sys.exit(app.exec_())

output

本文链接:https://www.f2er.com/3162172.html

大家都在问