[PyQt] Event Handling - Mouse clicked

Target

1. Create a button "Click" on window

2. When the button is pressed, display message dialog "Button Clicked"


Source code

import sys
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *

class MyWindow(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("PyQT")
self.setGeometry(100, 100, 300, 400)

btn1 = QPushButton("Click", self)
btn1.move(20, 20)
btn1.clicked.connect(self.btn1_clicked)

def btn1_clicked(self):
QMessageBox.about(self, "Message", "Button clicked")

if __name__ == "__main__":
app = QApplication(sys.argv)
myWindow = MyWindow()
myWindow.show()
app.exec_()


Result



'Python' 카테고리의 다른 글

Anaconda Python  (0) 2017.02.02
[PyQt] Make a window with "Hello World"  (0) 2017.02.02
[PyQt] What is PyQt?  (0) 2017.02.02
Install PyCharm IDE  (0) 2017.02.02
[Python] print "Hello world"  (0) 2017.02.02