## Ex 3-1. 창 띄우기.
import sys
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QIcon, QPixmap
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QVBoxLayout, QLabel, QMessageBox
# importing random stuff, esp if there's a red line you can just click n import
class MyApp(QWidget):
def __init__(self): # constructor
super().__init__()
self.initUI()
def initUI(self): # insert everything here
# this (in java) = self (in python)
self.setWindowTitle('hazelnut')
self.move(300, 300) # from left top corner
self.resize(400, 200) # horizontal, vertical
self.show()
self.setWindowTitle('Icon')
self.setWindowIcon(QIcon('./iconic.jpg'))
self.setGeometry(300, 300, 300, 200)
self.show()
btn1 = QPushButton('Hazel')
btn1.clicked.connect(self.clickOnThis)
btn2 = QPushButton('Bella')
btn2.clicked.connect(self.clickyClick)
pixmap = QPixmap('./iconic.jpg')
lbl_img = QLabel()
lbl_img.setPixmap(pixmap)
lbl_size = QLabel('Width: ' + str(pixmap.width()) + ', Height: ' + str(pixmap.height()))
lbl_size.setAlignment(Qt.AlignCenter)
vbox = QVBoxLayout()
vbox.addWidget(lbl_img)
vbox.addWidget(lbl_size)
self.setLayout(vbox)
self.setWindowTitle('QPixmap')
self.move(300, 300)
self.show()
vbox = QVBoxLayout()
vbox.addWidget(btn1)
vbox.addWidget(btn2)
self.setLayout(vbox)
def clickOnThis(self, event):
reply = QMessageBox.question(self, 'Message', 'Is Hazel da GOAT?',
QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
if reply == QMessageBox.Yes:
print('Hazel da GOAT')
else:
print("NOT TRUE!!!!")
def clickyClick(self, event):
reply = QMessageBox.question(self, 'Message', 'Is Bella da NOOB?',
QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
if reply == QMessageBox.Yes:
print("Bella da NOOB")
else:
print("NOT TRUE!!!!")
# just leave this be
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = MyApp()
sys.exit(app.exec_())
top of page
기능을 테스트하려면 라이브 사이트로 이동하세요.
창띄우기 20240908
창띄우기 20240908
댓글 1개
좋아요
댓글(1)
bottom of page
구글검색 pyqt5
https://wikidocs.net/21849