Demo entry 4085399

Test

   

Submitted by anonymous on Mar 17, 2016 at 16:42
Language: Python 3. Code size: 1.1 kB.

#!/usr/bin/python
# -*- coding: utf-8 -*-
#
from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QLineEdit, QPushButton

class HelloWidget(QWidget):
    def __init__(self):
        QWidget.__init__(self)
        self.setupUi()
        self.button.clicked.connect(self.onClick)

    def setupUi(self):
        self.resize(300, 150)
        self.setWindowTitle("HelloWidget")
        self.label = QLabel(self)
        self.label.setGeometry(10, 10, 90, 20)
        self.label.setText("Name: ")
        self.edit = QLineEdit(self)
        self.edit.setGeometry(100, 10, 90, 20)
        self.button = QPushButton(self)
        self.button.setGeometry(200, 10, 90, 20)
        self.button.setText("Greet")
        self.result = QLabel(self)
        self.result.setGeometry(10, 40, 190, 20)

    def onClick(self, event):
    	name = str(self.edit.text())
    	self.result.setText("Hello %s!" % name)

if __name__ == '__main__':
    application = QApplication([])
    window = HelloWidget()
    window.show()
    application.exec_()

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).