SHARE
TWEET

Python QDialog Example

a guest Dec 7th, 2017 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import sys, os
  2. from PyQt4 import QtCore, QtGui
  3. from PyQt4.QtCore import Qt
  4.    
  5. class Dialog(QtGui.QDialog):
  6.     def __init__(self, parent = None):
  7.         super(Dialog, self).__init__(parent)
  8.         # widgets
  9.         self.edit1 = QtGui.QLineEdit()
  10.         self.edit2 = QtGui.QLineEdit()
  11.         self.btnOk = QtGui.QPushButton("Ok")
  12.         self.btnCancel = QtGui.QPushButton("Cancel")
  13.         self.btnHelp = QtGui.QPushButton("Help")
  14.         self.btnOk.setDefault(True)
  15.        
  16.         # layout
  17.         layout = QtGui.QVBoxLayout()
  18.         layout.addWidget(self.edit1)
  19.         layout.addWidget(self.edit2)
  20.         layout.addWidget(self.btnHelp)
  21.         layout.addWidget(self.btnOk)
  22.         layout.addWidget(self.btnCancel)
  23.         self.setLayout(layout)
  24.        
  25.         # signals
  26.         self.btnOk.clicked.connect(self.accept)
  27.         self.btnCancel.clicked.connect(self.reject)
  28.         self.btnHelp.clicked.connect(self.help)
  29.        
  30.     def help(self):
  31.         print("HELP...")
  32.  
  33. if __name__ == '__main__':
  34.     app = QtGui.QApplication(sys.argv)
  35.     dialog = Dialog()
  36.     result = dialog.exec_()
  37.     print(result)
  38.     sys.exit(0)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top