[英]PYQT5 add multiple images to window
我無法將兩個圖像添加到 Python 中的一個 window。 我查看了論壇上的其他主題,但它們沒有幫助。 QImage function 僅添加 1。 我希望原始圖像和我將進行更改的圖像都出現在程序中。 我只是無法添加原始圖像,對普通圖像進行操作等。我可以做到,沒問題。 他們說 QPixmap 什么的,但我不明白。 附上代碼:
def openImage(self,image_label):
image_file, _ = QFileDialog.getOpenFileName(self, "Open Image",
"", "PNG Files (*.png);;JPG Files (*.jpeg *.jpg );;Bitmap Files (*.bmp);;\
GIF Files (*.gif)")
if image_file:
self.parent.zoom_factor = 1
self.parent.print_act.setEnabled(True)
self.parent.updateActions()
self.parent.brightness_slider.setValue(0)
image_format = self.image.format()
self.image = QImage(image_file) #manipulated area
self.original_image = self.image.copy() #Original image
self.setPixmap(QPixmap().fromImage(self.image))
self.resize(self.pixmap().size())
elif image_file == "":
# User selected Cancel
pass
else:
QMessageBox.information(self, "Error",
"Unable to open image.", QMessageBox.Ok)
我只是把它扔掉了,所以你可以理解我想怎么做。 這不是因為你從頭開始為我編寫一個項目。
除了使用 QImage,您可以使用 QLabel 並應用 QPixmap 並將它們排列在垂直布局中。
像這樣:
from PyQt5.QtWidgets import QLabel
from PyQt5.QtGui import QPixmap
image_one = QLabel()
image_two = QLabel()
def set_image_one(image_path):
image_one.setPixmap(QPixmap(image_path))
def set_image_one(image_path):
image_two.setPixmap(QPixmap(image_path))
根據您的要求調用這些函數並將獲取的文件路徑傳遞給它們。
謝謝
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.