i learned by this vid
https://www.youtube.com/watch?v=MOItX2aKTGc
from PyQt5.QtWidgets import *
def main():
app = QApplication([])
window = QWidget()
window.show()
app.exec_()
if __name__ == '__main__':
main()
from PyQt5.QtWidgets import *
from PyQt5.QtGui import QFont
def main():
app = QApplication([])
window = QWidget()
window.setGeometry(100, 100, 200, 300) # window size
window.setWindowTitle("My Simple GUI")
label = QLabel(window)
label.setText("Press The Button Below!")
label.setFont(QFont("Arial", 16)) # set font
label.move(50, 100) # move the label
window.show()
app.exec_()
if __name__ == '__main__':
main()
from PyQt5.QtWidgets import *
from PyQt5.QtGui import QFont
def main():
app = QApplication([])
window = QWidget()
window.setGeometry(100, 100, 200, 300) # window size
window.setWindowTitle("My Simple GUI")
layout = QVBoxLayout(window) # vertical stack layout # 😍😘🥰
lable = QLabel("Press The Button Below!") # element 1
button = QPushButton("Press Me!") # element 2
layout.addWidget(lable)
layout.addWidget(button)
window.setLayout(layout)
window.show()
app.exec_()
if __name__ == '__main__':
main()
from PyQt5.QtWidgets import *
from PyQt5.QtGui import QFont
def main():
app = QApplication([])
window = QWidget()
window.setGeometry(100, 100, 200, 300) # window size
window.setWindowTitle("My Simple GUI")
layout = QVBoxLayout(window) # vertical stack layout
lable = QLabel("Press The Button Below!") # element 1
button = QPushButton("Press Me!") # element 2
button.clicked.connect(on_clicked) # 😎😍😘🥰 함수 연결
layout.addWidget(lable)
layout.addWidget(button)
window.setLayout(layout)
window.show()
app.exec_()
# 😎😍😘🥰 함수 정의
def on_clicked():
print("Hello World")
if __name__ == '__main__':
main()
from PyQt5.QtWidgets import *
from PyQt5.QtGui import QFont
def main():
app = QApplication([])
window = QWidget()
window.setGeometry(100, 100, 200, 300) # window size
window.setWindowTitle("My Simple GUI")
layout = QVBoxLayout(window) # vertical stack layout
lable = QLabel("Press The Button Below!") # element 1
button = QPushButton("Press Me!") # element 2
message_button = QPushButton("message_button") # 😁😂🤣 message 버튼 추가
button.clicked.connect(on_clicked)
message_button.clicked.connect(qt_message) # message 버튼에 기능(함수)연결
layout.addWidget(lable)
layout.addWidget(button)
layout.addWidget(message_button) # message 버튼 화면에 배치
window.setLayout(layout)
window.show()
app.exec_()
def on_clicked():
print("Hello World")
def qt_message(): # 😀😁😂 message 함수 정의
message = QMessageBox()
message.setText("Hello World")
message.exec_()
if __name__ == '__main__':
main()
from PyQt5.QtWidgets import *
from PyQt5.QtGui import QFont
def main():
app = QApplication([])
window = QWidget()
window.setGeometry(100, 100, 200, 300) # window size
window.setWindowTitle("My Simple GUI")
layout = QVBoxLayout(window) # vertical stack layout
lable = QLabel("Press The Button Below!") # element 1
textbox = QTextEdit() # 😀😁😂
message_button = QPushButton("message_button") # element 3
message_button.clicked.connect(lambda : qt_message(textbox.toPlainText())) # 😀😁😂
layout.addWidget(lable)
layout.addWidget(textbox)
layout.addWidget(button)
layout.addWidget(message_button)
window.setLayout(layout)
window.show()
app.exec_()
def qt_message(msg):
message = QMessageBox()
message.setText(msg)
message.exec_()
if __name__ == '__main__':
main()
이상 PyQt5 창을 생성하고, 함수를 만들고 버튼에 함수를 연결하며, 입력창을 이용해 함수에 매개변수를 전달하는 등의 기능을 모두 구현해 보았다. 이제 앞으로는 좀 더 다양한 프로그램을 시도해보면 실력이 향상될 것이다.