code:
import sys
from PySide.QtCore import *
from PySide.QtGui import *
def main():
app = QApplication(sys.argv)
main = QMainWindow()
main.setWindowTitle("First GUI")
form_widget = QWidget()
form_widget.layout = QFormLayout()
form_widget.layout.addRow(QLabel("city 1"), QLabel("delhi"))
form_widget.layout.addRow(QLabel("city 2"), QLabel("chennai"))
main.setCentralWidget(form_widget)
main.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
Above code opened an empty window with "First GUI" as title.
But rows were not added to that window. Why ? How to correct this ?
addRowdoesn't need the explicit instantiation ofQLabelfor the first argument. You can invoke it simply asform_widget.layout.addRow("city 1", QLabel("delhi")).