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

Jump to: navigation, search
(Created page with '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 ot...')
 
m (Text replace - "</code>" to "</syntaxhighlight>")
 
(11 intermediate revisions by 2 users not shown)
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).
+
{|align="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). Save the code below as a file named hello.
  
<code>
+
<syntaxhighlight lang="python">
 
from PyQt4.QtGui import *
 
from PyQt4.QtGui import *
 
from PyQt4.QtCore import *
 
from PyQt4.QtCore import *
Line 29: Line 32:
 
sys.exit(app.exec_())
 
sys.exit(app.exec_())
  
</code>
+
</syntaxhighlight>
 +
 
 +
Call this program like this:
 +
python hello

Latest revision as of 21:54, 29 June 2011

Pykde.png

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")
 
#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)
 
# Connect buttons to actions
QObject.connect(button1,SIGNAL("clicked()"),greet)
QObject.connect(button2,SIGNAL("clicked()"),app.exit)
 
win.show()
#Start the evnt loop
sys.exit(app.exec_())

Call this program like this:

python hello

This page was last modified on 29 June 2011, at 21:54. This page has been accessed 3,835 times. Content is available under Creative Commons License SA 3.0 as well as the GNU Free Documentation License 1.2.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V.Legal