Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- from PyQt4 import QtGui
- class PictureViewer( QtGui.QMainWindow ):
- def __init__( self ):
- super( PictureViewer, self ).__init__()
- self.initUI()
- def initUI( self ):
- openAction = QtGui.QAction( '&Open', self )
- openAction.setShortcut( 'Ctrl+O' )
- openAction.triggered.connect( self.onOpen )
- menubar = self.menuBar()
- fileMenu = menubar.addMenu( '&File' )
- fileMenu.addAction( openAction )
- main = QtGui.QWidget( self )
- self.pic = QtGui.QLabel()
- scrollArea = QtGui.QScrollArea()
- scrollArea.setWidgetResizable( True )
- scrollArea.setWidget( self.pic )
- hbox = QtGui.QHBoxLayout()
- hbox.addWidget( scrollArea )
- main.setLayout( hbox )
- self.setCentralWidget( main )
- self.resize( 640, 480 )
- self.center()
- self.setWindowTitle( 'Picture Viewer' )
- self.show()
- def center( self ):
- qr = self.frameGeometry()
- cp = QtGui.QDesktopWidget().availableGeometry().center()
- qr.moveCenter( cp )
- self.move( qr.topLeft() )
- def onOpen( self ):
- fname = QtGui.QFileDialog.getOpenFileName( self, 'Open image', '', 'Images (*.png *.jpg *.bmp)' )
- if( fname != None and fname != "" ):
- pixmap = QtGui.QPixmap( fname )
- self.pic.setPixmap( pixmap )
- def main():
- app = QtGui.QApplication( sys.argv )
- pv = PictureViewer()
- sys.exit( app.exec_() )
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement