5

Hello guys i am learning pyqt5 from a series of tutorials at youtube and i didn't get why QtWidgets.QApplication have the argument sys.argv i am not familiar with sys library i read the documentation but still have no clue so sorry i know this question is kind of a noobish.

import sys
from PyQt5 import QtWidgets


def window():
    app = QtWidgets.QApplication(sys.argv)
    w=QtWidgets.QWidget()
    w.show()
    sys.exit(app.exec_())

window()
SethMMorton
  • 45,752
  • 12
  • 65
  • 86
walrus
  • 65
  • 1
  • 5
  • Possible duplicate of [what is sys.argv used for in python PyQt4](https://stackoverflow.com/questions/36088269/what-is-sys-argv-used-for-in-python-pyqt4) – ekhumoro Sep 01 '17 at 02:06
  • 1
    Possible duplicate of [Why do I need "sys.argv" to start a QApplication in PyQt?](https://stackoverflow.com/questions/27940378/why-do-i-need-sys-argv-to-start-a-qapplication-in-pyqt) – SethMMorton Sep 01 '17 at 02:22

1 Answers1

0

From the docs:

sys.argv

The list of command line arguments passed to a Python script. argv[0] is the script name (it is operating system dependent whether this is a full pathname or not). If the command was executed using the -c command line option to the interpreter, argv[0] is set to the string '-c'. If no script name was passed to the Python interpreter, argv[0] is the empty string.

To loop over the standard input, or the list of files given on the command line, see the fileinput module.

Example:

python foo.py
sys.argv = ['foo.py']

python foo.py bar baz
sys.argv = ['foo.py', 'bar', 'baz']

For your specific question, see this link: Why do I need "sys.argv" to start a QApplication in PyQt?

Basically, a QT application can take initialization arguments from the command line, the top answer should point you to a list of them with an explanation of what they do.

Saedeas
  • 1,548
  • 8
  • 17
  • "i didn't get why QtWidgets.QApplication have the argument sys.argv". While this answer does state what is `sys.argv`, it does *not* explain why `QtWidgets.QApplication` requires it as an argument. – SethMMorton Sep 01 '17 at 02:01
  • Edit contains answer. The old title was unclear. This should probably be closed as a duplicate. – Saedeas Sep 01 '17 at 02:17
  • Why answer a question based only on the title? – SethMMorton Sep 01 '17 at 02:21
  • "have the argument sys.argv i am not familiar with sys library i read the documentation but still have no clue so sorry i know this question is kind of a noobish." I thought an explanation of what sys.v was and the implications when it was used as the arguments to a constructor were fairly obvious. My bad, I have clarified. – Saedeas Sep 01 '17 at 02:23
  • so sys.argv is basicly what i use in my discord bot e.g. !bot_name play – walrus Sep 01 '17 at 02:53
  • Essentially. When you're using the command line, you often need to pass arguments to the program you're calling (e.g copy needs a place to copy from and a place to copy to). One of the things the sys library allows you to do is use arguments passed in when your program is called inside your python code. – Saedeas Sep 01 '17 at 03:17
  • @walrus. Please read [this answer](https://stackoverflow.com/a/36093536/984421) to the other duplicate I lnked to. It should make everything clear. – ekhumoro Sep 01 '17 at 13:00