what is sys.argv used for in python PyQt4

Viewed 3578

I'm still a beginner when it comes to programming, and I'm especially new when it comes GUI programming. I'm using python with PyQt4 and im following a tutorial guide. The following code block is relatively easy to follow:

import sys
from PyQt4 import QtGui
def window():
    app = QtGui.QApplication(sys.argv)
    w = QtGui.QWidget()
    b= QtGui.QLabel(w)
    b.setText("Hello World!")
    w.setGeometry(100,100,200,50)
    b.move(50,20)
    w.setWindowTitle(“PyQt”)
    w.show()
    sys.exit(app.exec_())
if __name__ == '__main__':
    window()

I can follow whats going on here quite well, but could someone explain to me what the sys.argv is actually doing? I don't want to just blindly put this in every time in the hope that it will make my code work!

5 Answers

QApplication can optionally accept additional command line arguments, say you have a PyQT or PySide program with CheckBox and Slider, and you run it with the following command:

$ python3 checkbox_slider.py -style fusion  

you'll find the style is different, that mean sys.argv has its practical use in some cases. see more argument options from official website

Related