Created
January 23, 2023 15:11
-
-
Save MartGro/cd20388f27a9998b7a0f312f8387c5e2 to your computer and use it in GitHub Desktop.
Simple Image Display Widget in Napari
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.QtWidgets import QApplication, QLabel | |
from PyQt5.QtGui import QPixmap | |
class ImageWidget(QLabel): | |
""" | |
A QLabel widget that displays an image from a file | |
""" | |
def __init__(self, parent=None): | |
""" | |
Initialize the ImageWidget | |
""" | |
super().__init__(parent) | |
def set_image(self, file_path): | |
""" | |
Set the image of the widget from a file path | |
Parameters: | |
file_path (str): path to the image file | |
""" | |
pixmap = QPixmap(file_path) | |
self.setPixmap(pixmap) | |
# Create an instance of the ImageWidget | |
image_widget = ImageWidget() | |
# Set the image to be displayed in the widget | |
image_widget.set_image('colormap_white.png') | |
#Add the widget to napari dock area | |
viewer.window.add_dock_widget(image_widget,area="left") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment