Difference between revisions of "Development/Tutorials/Python-hello world"

Jump to: navigation, search
Line 1: Line 1:
 
This is an example application in python using KDE bindings. It builds up two buttons. You need a layout for this, that is also demonstrated. One button exits the program, the other button does a trivial action as a demo, in this case, print "hello world" to the console (more exactly: to stdout).
 
This is an example application in python using KDE bindings. It builds up two buttons. You need a layout for this, that is also demonstrated. One button exits the program, the other button does a trivial action as a demo, in this case, print "hello world" to the console (more exactly: to stdout).
  
{{Image:Pykde.png}}
+
{{File:Pykde.png}}
  
 
<code python>
 
<code python>

Revision as of 10:47, 15 August 2010

This is an example application in python using KDE bindings. It builds up two buttons. You need a layout for this, that is also demonstrated. One button exits the program, the other button does a trivial action as a demo, in this case, print "hello world" to the console (more exactly: to stdout).

GUI of hello world application for KDE Python bindings.

from PyQt4.QtGui import * from PyQt4.QtCore import * import sys

def greet():

 print ("hello world")
  1. First we create a QApplication and QPushButton

app=QApplication(sys.argv)

win = QWidget() qgl = QGridLayout(win) button1=QPushButton(win) button2=QPushButton(win) button1.setText("greet") button2.setText("exit") qgl.addWidget(button1) qgl.addWidget(button2)

  1. Connect buttons to actions

QObject.connect(button1,SIGNAL("clicked()"),greet) QObject.connect(button2,SIGNAL("clicked()"),app.exit)

win.show()

  1. Start the evnt loop

sys.exit(app.exec_())


KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V.Legal