반응형
/*********************************************************************************************************
-- Title : [PyQt4] Message Box 구현
-- Reference : pythonspot.com
-- Key word : 파이썬 python pyqt qt qt4 gui 메세지 박스 msg warning information about 커스텀 박스
메시지박스 메시지 박스
*********************************************************************************************************/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | # -*- coding: utf-8 -*- import sys from PyQt4.QtCore import pyqtSlot from PyQt4.QtGui import * # ------------------------------------------ # -- Create window # ------------------------------------------ myApp = QApplication(sys.argv) # Create an PyQT4 application object. w = QWidget() # The QWidget widget is the base class w.setWindowTitle('Title Message') w.resize(400, 200) # ------------------------------------------ # -- Create textbox # ------------------------------------------ myTextbox = QLineEdit(w) myTextbox.move(20, 20) myTextbox.resize(360,40) # ------------------------------------------ # -- Create a button in the window # ------------------------------------------ myButton1 = QPushButton('msg', w) myButton1.move(20,80) myButton2 = QPushButton('warning', w) myButton2.move(100, 80) myButton3 = QPushButton('information', w) myButton3.move(180, 80) myButton4 = QPushButton('critical', w) myButton4.move(260, 80) myButton5 = QPushButton('about', w) myButton5.move(20, 110) myButton0 = QPushButton('exit', w) myButton0.move(100, 110) myButton6 = QPushButton('customized', w) myButton6.move(20, 140) # ------------------------------------------ # -- Create the actions # ------------------------------------------ @pyqtSlot() def on_click0(): w.close() @pyqtSlot() def on_click1(): result = QMessageBox.question(w, 'Message', "Do you like Python?", QMessageBox.Yes | QMessageBox.No, QMessageBox.No) if result == QMessageBox.Yes: myTextbox.setText("Clicked YES on Msg.") else: myTextbox.setText("Clicked NO on Msg.") @pyqtSlot() def on_click2(): result = QMessageBox.warning(w, "Warning", "Are you sure you leave?") if result == QMessageBox.Ok: myTextbox.setText("Clicked OK on Warning.") @pyqtSlot() def on_click3(): result = QMessageBox.information(w, "Information", "Join us 123@123.com") if result == QMessageBox.Ok: myTextbox.setText("Clicked OK on Information.") @pyqtSlot() def on_click4(): result = QMessageBox.critical(w, "Critical", "No disk space left.") if result == QMessageBox.Ok: myTextbox.setText("Clicked OK on Critical.") @pyqtSlot() def on_click5(): result = QMessageBox.about(w, "About", "A messagebox about...") print result # None이 리턴됨 @pyqtSlot() def on_click6(): msgbox = QMessageBox(w) msgbox.setText('Don''t buy anything on impluse!') msgbox.addButton(QPushButton('Approve'), QMessageBox.YesRole) msgbox.addButton(QPushButton('Reject'), QMessageBox.NoRole) msgbox.addButton(QPushButton('Cancel'), QMessageBox.RejectRole) result = msgbox.exec_() print result # 0,1,2가 리턴됨 # ------------------------------------------ # -- Connect the signals to the slots # ------------------------------------------ myButton0.clicked.connect(on_click0) myButton1.clicked.connect(on_click1) myButton2.clicked.connect(on_click2) myButton3.clicked.connect(on_click3) myButton4.clicked.connect(on_click4) myButton5.clicked.connect(on_click5) myButton6.clicked.connect(on_click6) # ------------------------------------------ # -- Show the window and run the app # ------------------------------------------ w.show() myApp.exec_() | cs |
반응형