Skip to content

Instantly share code, notes, and snippets.

@lmzach09
Created September 8, 2019 21:59
Show Gist options
  • Save lmzach09/0919cb3ab5d92991d0b034164d6515af to your computer and use it in GitHub Desktop.
Save lmzach09/0919cb3ab5d92991d0b034164d6515af to your computer and use it in GitHub Desktop.
creating a desktop app window in python with pyqt
class App(QWidget):
def __init__(self):
super().__init__()
## Set main window attributes
self.title = 'Photo Album Viewer'
self.left = 0
self.top = 0
self.width = 800
self.height = 600
self.resizeEvent = lambda e : self.on_main_window_resize(e)
## Make 2 widgets, one to select an image and one to display an image
self.display_image = DisplayImage(self)
self.image_file_selector = ImageFileSelector( \
album_path=DEFAULT_IMAGE_ALBUM_DIRECTORY, \
display_image=self.display_image)
scroll = QScrollArea()
scroll.setWidgetResizable(True)
scroll.setFixedWidth(140)
nav = scroll
nav.setWidget(self.image_file_selector)
## Add the 2 widgets to the main window layout
layout = QGridLayout(self)
layout.addWidget(nav, 0, 0, Qt.AlignLeft)
layout.addWidget(self.display_image.label, 0, 1, Qt.AlignRight)
self.init_ui()
def init_ui(self):
self.setWindowTitle(self.title)
self.setGeometry(self.left, self.top, self.width, self.height)
self.show()
## Set the display image size based on the new window size
def on_main_window_resize(self, event):
self.display_image.on_main_window_resize(event)
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = App()
sys.exit(app.exec_())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment