G2A Many GEOs
SHARE
TWEET

PyQt Save/Restore

a guest Apr 6th, 2020 177 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Simple Program with 2 Line Edits and 1 Checkbox to learn how to save/restore state.  
  2. from PyQt5 import QtCore, QtGui, QtWidgets
  3.  
  4.  
  5. class Ui_MainWindow(object):
  6.     def setupUi(self, MainWindow):
  7.         MainWindow.setObjectName("MainWindow")
  8.         MainWindow.resize(231, 166)
  9.         self.centralwidget = QtWidgets.QWidget(MainWindow)
  10.         self.centralwidget.setObjectName("centralwidget")
  11.         self.gridLayout_2 = QtWidgets.QGridLayout(self.centralwidget)
  12.         self.gridLayout_2.setObjectName("gridLayout_2")
  13.         self.widget = QtWidgets.QWidget(self.centralwidget)
  14.         self.widget.setObjectName("widget")
  15.         self.gridLayout_3 = QtWidgets.QGridLayout(self.widget)
  16.         self.gridLayout_3.setObjectName("gridLayout_3")
  17.         self.frame = QtWidgets.QFrame(self.widget)
  18.         self.frame.setFrameShape(QtWidgets.QFrame.StyledPanel)
  19.         self.frame.setFrameShadow(QtWidgets.QFrame.Raised)
  20.         self.frame.setObjectName("frame")
  21.         self.gridLayout = QtWidgets.QGridLayout(self.frame)
  22.         self.gridLayout.setObjectName("gridLayout")
  23.         self.label = QtWidgets.QLabel(self.frame)
  24.         self.label.setObjectName("label")
  25.         self.gridLayout.addWidget(self.label, 0, 0, 1, 1)
  26.         self.lineEdit = QtWidgets.QLineEdit(self.frame)
  27.         self.lineEdit.setObjectName("lineEdit")
  28.         self.gridLayout.addWidget(self.lineEdit, 0, 1, 1, 1)
  29.         self.label_2 = QtWidgets.QLabel(self.frame)
  30.         self.label_2.setObjectName("label_2")
  31.         self.gridLayout.addWidget(self.label_2, 1, 0, 1, 1)
  32.         self.lineEdit_2 = QtWidgets.QLineEdit(self.frame)
  33.         self.lineEdit_2.setObjectName("lineEdit_2")
  34.         self.gridLayout.addWidget(self.lineEdit_2, 1, 1, 1, 1)
  35.         self.checkBox = QtWidgets.QCheckBox(self.frame)
  36.         self.checkBox.setObjectName("checkBox")
  37.         self.gridLayout.addWidget(self.checkBox, 2, 0, 1, 1)
  38.         self.gridLayout_3.addWidget(self.frame, 0, 0, 1, 1)
  39.         self.gridLayout_2.addWidget(self.widget, 0, 0, 1, 1)
  40.         MainWindow.setCentralWidget(self.centralwidget)
  41.         self.menubar = QtWidgets.QMenuBar(MainWindow)
  42.         self.menubar.setGeometry(QtCore.QRect(0, 0, 231, 21))
  43.         self.menubar.setObjectName("menubar")
  44.         MainWindow.setMenuBar(self.menubar)
  45.         self.statusbar = QtWidgets.QStatusBar(MainWindow)
  46.         self.statusbar.setObjectName("statusbar")
  47.         MainWindow.setStatusBar(self.statusbar)
  48.  
  49.         self.retranslateUi(MainWindow)
  50.         QtCore.QMetaObject.connectSlotsByName(MainWindow)
  51.  
  52.     def retranslateUi(self, MainWindow):
  53.         _translate = QtCore.QCoreApplication.translate
  54.         MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
  55.         self.label.setText(_translate("MainWindow", "User"))
  56.         self.label_2.setText(_translate("MainWindow", "Country"))
  57.         self.checkBox.setText(_translate("MainWindow", "CheckBox"))
  58.  
  59.  
  60. if __name__ == "__main__":
  61.     import sys
  62.     app = QtWidgets.QApplication(sys.argv)
  63.     MainWindow = QtWidgets.QMainWindow()
  64.     ui = Ui_MainWindow()
  65.     ui.setupUi(MainWindow)
  66.     MainWindow.show()
  67.     sys.exit(app.exec_())
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
Top