pyqt - 창(windows)
필요한 패키지 설치
$ pip install pyqt5
$ sudo apt-get install qt5-default
$ sudo apt-get install libqt5x11extras5
$ pip install opencv-python==4.1.2.30
창 띄우기
import sys
from PyQt5.QtWidgets import QApplication, QWidget
class MyApp(QWidget):
def __init__(self):
super().__init__() # 부모 클래스(QWidget)의 __init__ 함수를 그대로 가져와 사용
self.initUI()
def initUI(self):
self.setWindowTitle('My First Application')
self.move(300, 300)
self.resize(400, 200)
self.show()
def center(self): # 창을 가운데로 띄우기
qr = self.frameGeometry()
cp = QDesktopWidget().availableGeometry().center()
qr.moveCenter(cp)
self.move(qr.topLeft())
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = MyApp()
sys.exit(app.exec_())
창 닫기
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton
from PyQt5.QtCore import QCoreApplication
class MyApp(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
btn = QPushButton('Quit', self) # 푸시 버튼
btn.move(50, 50)
btn.resize(btn.sizeHint())
btn.clicked.connect(QCoreApplication.instance().quit)
# 버튼이 클릭되면(signal) 어떤 함수를 호출(slot)하는지 설정하기
self.setWindowTitle('Quit Button')
self.setGeometry(300, 300, 300, 200)
self.show()
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = MyApp()
sys.exit(app.exec_())
창에 아이콘 넣기
import sys
from PyQt5.QtWidgets import QApplication, QWidget
from PyQt5.QtGui import QIcon
class MyApp(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.setWindowTitle('Icon')
self.setWindowIcon(QIcon('web.png'))
self.setGeometry(300, 300, 300, 200)
self.show()
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = MyApp()
sys.exit(app.exec_())
Author And Source
이 문제에 관하여(pyqt - 창(windows)), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@bangsy/pyqt-1저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)