Created
February 12, 2021 22:01
-
-
Save driscollis/364562ffa915689b76c3586e9995e725 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
from PIL import Image, ImageQt | |
from PyQt5.QtGui import QPixmap, QImage | |
from PyQt5.QtWidgets import QWidget, QLabel | |
from PyQt5.QtWidgets import QVBoxLayout, QApplication | |
class ImageViewer(QWidget): | |
def __init__(self): | |
QWidget.__init__(self) | |
self.setWindowTitle("PyQt Image Viewer") | |
# Open up image in Pillow | |
image = Image.open("pink_flower.jpg") | |
qt_image = ImageQt.ImageQt(image) | |
pixmap = QPixmap.fromImage(qt_image) | |
self.image_label = QLabel('') | |
self.image_label.setPixmap(pixmap) | |
self.main_layout = QVBoxLayout() | |
self.main_layout.addWidget(self.image_label) | |
self.setLayout(self.main_layout) | |
if __name__ == "__main__": | |
app = QApplication(sys.argv) | |
viewer = ImageViewer() | |
viewer.show() | |
app.exec_() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
from PyQt5.QtGui import QPixmap | |
from PyQt5.QtWidgets import QWidget, QLabel | |
from PyQt5.QtWidgets import QVBoxLayout, QApplication | |
class ImageViewer(QWidget): | |
def __init__(self): | |
QWidget.__init__(self) | |
self.setWindowTitle("PyQt Image Viewer") | |
self.image_label = QLabel() | |
self.image_label.setPixmap(QPixmap('./pink_flower.jpg')) | |
self.main_layout = QVBoxLayout() | |
self.main_layout.addWidget(self.image_label) | |
self.setLayout(self.main_layout) | |
if __name__ == "__main__": | |
app = QApplication(sys.argv) | |
viewer = ImageViewer() | |
viewer.show() | |
app.exec_() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment