This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
from PyQt5 import QtWidgets #PyQt4 : QtGui | |
from PyQt5 import uic | |
class HelloQtForm(QtWidgets.QDialog): | |
def __init__(self, parent=None): | |
QtWidgets.QDialog.__init__(self, parent) | |
self.ui = uic.loadUi("HelloPyQt.ui", self) | |
self.ui.show() | |
if __name__ == '__main__': # only execute when directly run this file | |
app = QtWidgets.QApplication(sys.argv) | |
W = HelloQtForm() | |
sys.exit(app.exec()) |
PyQt4 와 PyQt5는 서로 호환되지 않습니다.
PyQt4 에서 PyQt5로 오면서 QtGui 가 QtGui, QtWidgets, QtPrintSupport 로 분리되었습니다.
QtWidgets.QDialog 를 상속받은 HelloQtForm class를 만들어서 초기화 method (__init__) 에 ui 파일을 load 하고 화면에 보이도록 하였습니다.
if __name__ == '__main__' 의 의미는 해당 파일이 다른 곳에서 module 처럼 이용되는 것이 아니라 직접 실행 했을 경우라는 뜻입니다.
module 개발시 아래에 test code 를 적어두는 용도로 사용하면 편리합니다.
댓글 없음:
댓글 쓰기