Python Forum
Raw Image Data Viewer using tkinter
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Raw Image Data Viewer using tkinter
#2
Pyside2 version. Image formats are png, jpg, ico, and bmp. The jpg images seem to take a few sewconds to display. Maybe because the files are large?

#! /usr/bin/env python3

import sys
from skimage.io import imread
from PySide2.QtWidgets import QApplication, QMainWindow, QWidget, \
QLabel, QPushButton, QVBoxLayout, QHBoxLayout, QFrame, QFileDialog, \
QListView, QListWidget
from PySide2.QtGui import QCursor, QPixmap
from PySide2.QtCore import Qt

class MainWindow(QMainWindow):

    def __init__(self):
        super(MainWindow, self).__init__()

        self.setWindowTitle("Raw Image Viewer")
        self.setFixedWidth(800)

        main_layout = QVBoxLayout()
        title_layout = QHBoxLayout()
        layout2 = QHBoxLayout()
        layout3 = QHBoxLayout()


        main_layout.addLayout(title_layout)
        main_layout.addLayout(layout2)
        main_layout.addLayout(layout3)


        title = QLabel('Raw Image Viewer')
        title.setAlignment(Qt.AlignVCenter | Qt.AlignHCenter)
        title.setFrameStyle(QFrame.StyledPanel)
        title.setStyleSheet('font-weight: bold; font-size: 30pt; padding: 10px; \
        color: rgb(100, 100, 200); background-color: rgb(198, 190, 200);')

        text_col = QLabel('Choose an image')
        text_col.setFrameStyle(QFrame.StyledPanel)
        text_col.setStyleSheet('font-size: 10pt; color: navy; padding: 5px; \
        background-color: rgb(198, 190, 200); text-decoration: underline;')

        btn = QPushButton('Get Image')
        btn.setStyleSheet('font-size: 12pt; padding: 5px; \
        color: steelblue; font-weight: bold;')
        btn.setAutoFillBackground(True)
        btn.setCursor(QCursor(Qt.PointingHandCursor))
        btn.clicked.connect(self.get_file)


        self.img_panel = QLabel()
        self.img_panel.setFrameStyle(QFrame.StyledPanel)

        self.img_panel.setScaledContents(True)
        self.img_panel.setFixedWidth(200)
        self.img_panel.setFixedHeight(200)

        img_data = QLabel()
        img_data.setFrameStyle(QFrame.StyledPanel)

        self.data = QListWidget()



        title_layout.addWidget(title)
        layout2.addWidget(text_col)
        layout2.addWidget(btn)
        layout3.addWidget(self.img_panel)
        layout3.addWidget(img_data)
        layout3.addWidget(self.data)



        widget = QWidget()

        widget.setLayout(main_layout)
        self.setCentralWidget(widget)


    def get_file(self):
        file = QFileDialog.getOpenFileName(self, 'Open File', '.', \
        'Image Files (*.png *.jpg *.bmp *.ico)')
        pixmap = QPixmap(file[0])
        self.img_panel.setPixmap(pixmap)

        self.data.clear()
        for lines in imread(file[0]):
            for line in lines:
                self.data.addItem(f'{line}')


app = QApplication(sys.argv)

window = MainWindow()
window.show()

app.exec_()
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply


Messages In This Thread
Raw Image Data Viewer using tkinter - by menator01 - Sep-06-2021, 02:25 AM
RE: Raw Image Data Viewer using tkinter - by menator01 - Sep-07-2021, 07:08 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Tkinter Image buttons menator01 1 2,692 Jan-29-2022, 06:04 PM
Last Post: Yoriz

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020