PyQt5 Beginner tutorial
Introduction
이것은 PyQt5 초보자 교본입니다.
이 교본은 가장 짧은 기간 안에 PyQt를 이해하고 실행하는 것을 도울 것입니다.
파이썬에 대한 기초 지식을 갖고 있는 것으로 가정합니다.
PyQt는 크로스 플랫폼 GUI 툴킷 Qt의 파이썬 바인딩 입니다.
이것은 GUI 프로그래밍에 대한 파이썬의 옵션 중 하나입니다.
대안으로는 PySide, PyGTK, wxPython 및 Tkinter가 있습니다.
PyQt는 비 상업용 응용 프로그램 (GPL 라이센스)의 개발에 가장 적합합니다.
상업적 응용 프로그램을 개발하려면, PySide가 매우 인기가 있으며, LGPL 라이센스하에 배포됩니다.
This is a PyQt5 beginner tutorial. It will help you get up and running with PyQt in the shortest possible time. A basic knowledge of Python is assumed.
PyQt is a Python binding of the cross-platform GUI toolkit Qt. It is one of Python's options for GUI programming. Other alternatives include PySide, PyGTK, wxPython, and Tkinter.
PyQt is best suited for development of non-commercial applications(GPL licence). If you want to develop commercail applications, PySide is quite plopular and is released under the LGPL licence.
Installing PyQt
파이썬의 최신 버전 (현재 3.3.3)이 필요합니다.
최신 버전이 설치되어 있는지 확인하고 시스템 경로에 실행 파일을 추가합니다.
이 옵션은 설치 프로그램 내에서 자동으로 사용할 수 있습니다.
이 작업이 완료되면, Riverbank 웹사이트에서 해당 바이너리를 다운로드하고 기본 설치를 선택합니다.
You will need the latest version of Python(currently 3.3.3). Make sure this is installed and that you add the executable to the system path. This option is automatically available from within the installer.
Once that is done, download an appropriate binary from the Riverbank website and choose the default installation options.
Writing your first script
Fairly simple no? Lines 1-2 define the necessary modules needed.
Line 4: QWidget is the base class of all user interface objects in PyQt5, so you are creating a new Form class that inherits from the base class, QWidget.
Lines 5-6: The default constructor for QWidget. The default constructor has no parent, and a widget with no parent is known as a window.
Lines 7-9: Here we add a label, a text edit box and a submit button.
Lines 12-15: We add a QVBoxLayout. QVBoxLayout class lines up our widgets vertically.
Line 17: This adds an event handler, the function submitContact() for our submit button.
Lines 19-21: We add a QGridLayout. QGridLayout lays the widgets out in a grid. Widgets can be positioned as shown using Cartesian co-ordinates.
Lines 23-24: Set the QGridLayout as the window's main layout. After that we set it's title.
Line 27: We get the text contain in the widget nameLine
.
Lines 29-35: If nameLine
contains no text we issue an alert. If there is some text in the variable, we issue another alert, this time including the string entered by the user.
The rest of the code should be easy to follow. We create an instance of the Form
object called screen.
The show() method will display the widget on screen.
We then begin the event handling loop for the application. The event handling loop waits for an event to occur and then dispatches it to perform some task. The event-handling loop continues to work until either the exit() method is called or the main widget is destroyed. The sys.exit() method ensures a clean exit, releasing memory resources.
To run the script simply invoke
python <name of script>
To give you this:
결론 Conclusion
이것은 매우 기초적인 교본이었습니다.
보다 광범위한 참조는 여기서 할 수 있습니다.
This was a very basic tutorial. A comprehensive reference can be found here.
'Python 배우기' 카테고리의 다른 글
Running phython programs (0) | 2016.03.05 |
---|---|
Applications for Python 파이썬 적용 (0) | 2016.03.05 |
First Steps (0) | 2016.01.05 |
Installation (0) | 2016.01.05 |
Introduction (0) | 2016.01.05 |
댓글