TutorialΒΆ
This example: https://bitbucket.org/leliel12/pycante/src/tip/example
Open QtDesigner [1] and make a QDialog like this one
- where:
- Is a QDialog with objectName Dialog.
- Is a QLineEdit with objectName lineEdit.
- Is a QLabel with objectName label.
- Is a QPushButton with objectName pushButton.
Save the design as Dialog.ui.
Create in the same directory where the Dialog.ui file live a Python script with the next code.
#!/usr/bin/env python # -*- coding: utf-8 -*- # "THE WISKEY-WARE LICENSE": # <juan@brainiac> wrote this file. As long as you retain this notice you # can do whatever you want with this stuff. If we meet some day, and you think # this stuff is worth it, you can buy me a WISKEY in return Juan #=============================================================================== # DOCS #=============================================================================== """This is a example from tutorial of pycante """ #=============================================================================== # IMPORTS #=============================================================================== import os from PyQt4 import QtCore, QtGui import pycante #=============================================================================== # CONSTANTS #=============================================================================== # The canonical way to determine the path of this file PATH = os.path.abspath(os.path.dirname(__file__)) # Bind the path of this file as UI path for picante UI_DIR = pycante.EDir(PATH) #=============================================================================== # CLASS #=============================================================================== # The class dialog extend the Dialog.ui file class Dialog(UI_DIR("Dialog.ui")): # when signal clicked of push button is emited execute this code. def on_pushButton_clicked(self): text = self.lineEdit.text() self.label.setText("Hello " + unicode(text) + "!") #=============================================================================== # RUN QT #=============================================================================== app = QtGui.QApplication([]) d = Dialog() d.show() app.exec_()
Save the file as “dialog.py” and run it with:
$ python dialog.py
This is a video with the expected behavior
[1] | http://qt.digia.com/Product/Developer-Tools/ |