Since I was studying Pyside2, I somehow understood QApplication
and QWindow
, which are the first to get caught, so I summarized them.
It's a very simple window.
import sys
from PySide2.QtWidgets import *
if __name__ == '__main__':
app = QApplication(sys.argv)
main_window = QWidget()
main_window.resize(600,200)
main_window.show()
sys.exit(app.exec_())
from PySide2.QtWidgets import *
I'm importing QtWidgets
. The QtWidgets
contains a class that creates the QWidget
, which is the base of the Window, and the QPushbutton
button.
from PySide2.QtWidgets import QApplication,QWidget
You can also impot by specifying a class as above without using * (wildcard).
import sys
Since sys.argv ()
is used, the sys module is also imported. We will discuss sys.argv ()
later.
if __name__ == '__main__':
ʻIf name =='main` is omitted because there are many explanations on the net.
app = QApplication(sys.argv)
Store QApplication
in the variable ʻapp.
QApplication` is like the basis for putting a GUI on.
main_window = QWidget()
The QWidget
is stored in the variable main_window
.
QWidget
is the window where you place the buttons and labels.
The relationship between QApplication
and QWindow
is like this.
main_window.resize(600,200)
Specify the Window size. If you change the value, the size will change. It seems that you can also change the color and shape.
main_window.show
Display the created main_window
=QWindow ()
.
sys.exit(app.exec_())
ʻApp.exec_ ()=
QApplication.exec_ ()creates a loop that keeps the Window displayed. If you do not loop, the displayed Window will disappear as soon as the program ends.
sys.exit_ () is a command to terminate the program. Waiting for the end of ʻapp.exec_ ()
.
ʻWhen the app.exec_ ()ends, it receives
0and terminates the program itself. If you do not write
sys.exit_ (), the following program will be executed after exiting ʻapp.exec_ ()
.
If you study Pyside, searching with PyQt has more information than Pyside. You can refer to this page for the difference between PyQt and Pyside. https://qiita.com/nullpo24/items/c70e02c26ef5cade9480
Recommended Posts