< Development‎ | Tutorials
Revision as of 20:34, 29 June 2011 by Neverendingo (talk | contribs) (Text replace - "<code python>" to "<syntaxhighlight lang="python">")

Development/Tutorials/Python-hello world

The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

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). Save the code below as a file named hello.

<syntaxhighlight lang="python"> from PyQt4.QtGui import * from PyQt4.QtCore import * import sys

def greet():

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


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)


  1. Start the evnt loop


Call this program like this:

python hello

This page was last edited on 29 June 2011, at 20:54. Content is available under Creative Commons License SA 4.0 unless otherwise noted.