Line 2: | Line 2: | ||
|[[image:Pykde.png|right]] | |[[image:Pykde.png|right]] | ||
|} | |} | ||
− | 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). Save the code below as a file named hello. |
− | + | ||
<code python> | <code python> | ||
Line 34: | Line 33: | ||
</code> | </code> | ||
+ | |||
+ | Call this program like this: | ||
+ | python hello |
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.
from PyQt4.QtGui import *
from PyQt4.QtCore import *
import sys
def greet():
print ("hello world")
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)
QObject.connect(button1,SIGNAL("clicked()"),greet) QObject.connect(button2,SIGNAL("clicked()"),app.exit)
win.show()
sys.exit(app.exec_())
Call this program like this:
python hello