tareq1988

Qt Button click and statusbar

Sep 29th, 2011
117
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/python
  2.  
  3. import sys
  4. from PyQt4 import QtGui, QtCore
  5.  
  6. class Example(QtGui.QMainWindow):
  7.  
  8.     def __init__ (self, parent=None):
  9.         super(Example, self).__init__()
  10.         self.initUI()
  11.        
  12.     def initUI(self):
  13.        
  14.         button1 = QtGui.QPushButton("Button 1", self)
  15.         button1.move(30, 50)
  16.        
  17.         button2 = QtGui.QPushButton("Button 2", self)
  18.         button2.move(150, 50)
  19.        
  20.         self.connect(button1, QtCore.SIGNAL('clicked()'), self.buttonClicked)
  21.         self.connect(button2, QtCore.SIGNAL('clicked()'), self.buttonClicked)
  22.        
  23.         self.statusBar()
  24.         self.setGeometry(300, 300, 350, 250)
  25.         self.setWindowTitle('Example: Signal - Slot')
  26.         self.show()
  27.        
  28.     def buttonClicked(self):
  29.         sender = self.sender()
  30.         self.statusBar().showMessage(sender.text() + ' was pressed');
  31.        
  32.  
  33. def main():
  34.     app = QtGui.QApplication(sys.argv)
  35.     qs = Example()
  36.     sys.exit(app.exec_())
  37.  
  38. if __name__ == '__main__':
  39.     main()
  40.    
  41.  
  42.  
RAW Paste Data