Hallo Welt! (PyQt)

Ich habe mein erstes Programm mit PyQt erstellt.

In guter Programmier-Tradition heißt es "Hallo Welt!", und zeigt einfach "Hallo Welt!" an.

Ich habe es allerdings recht ausführlich kommentiert, so dass ich denke, dass es PyQt-Neulingen ein paar interessante Einzelheiten zeigen und Programmier- und Python-Neulingen ein paar einfache erste Einsichten geben kann.

Ich habe es angehängt, stelle den Code aber auch diekt auf diese Seite, denn Python Code ist schön genug, dass ich ihn offen auf die Webseite stellen kann.

-----

#!/bin/env python
# encoding: utf-8

#######################################################
#                                                     #
# Hallo Welt!                                         #
# - Mein Erstes PyQt-Programm mit Kommentaren         #
#                                                     #
#   Copyright (C) 2007, Arne Babenhauserheide, GPL    #
#                                                     #
#   This program is free software; you can            #
# redistribute it and/or modify it under the terms of #
# the GNU General Public License as published by the  #
# Free Software Foundation; either version 2 of the   #
# License, or (at your option) any later version.     #
#                                                     #
# This program is distributed in the hope that it     #
# will be useful, but WITHOUT ANY WARRANTY; without   #
# even the implied warranty of MERCHANTABILITY or     #
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU      #
# General Public License for more details.            #
#                                                     #
# You should have received a copy of the GNU General  #
# Public License along with this program; if not,     #
# write to the Free Software Foundation, Inc., 51     #
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 #
# USA.                                                #
#                                                     #
#######################################################


# Erst holen wir das System-Framework. "sys"
# Qt Programme brauchen von ihm die 
# Kommandozeilenparameter. 

import sys

# Dann die benötigten Qt-Klassen. 
# Erstens das grundlegende Widget für Programme
# QApplication

from qt import QApplication

# und Zweitens einen Knopf, den wir beschriften wollen
# QPushButton

from qt import QPushButton

# und dann noch Signal und Slot, 
# damit ein Druck auf den Knopf
# das Programm beenden kann. 

from qt import SIGNAL, SLOT

# Jetzt können wir uns das Programm app definieren 
# und ihm die Kommandozeilenparameter übergeben: 

app=QApplication(sys.argv)

# Der Knopf ist ähnlich schnell geschrieben. 
# Er erhält den Text "Hallo Welt!\nIch kann 
# (ein bisschen) PyQt!"
# Das \n erzeugt einen Zeilenumbruch. 
# Einfallsreicherweise nennen wir ihn "button". 

button=QPushButton("Hallo Welt!\nIch kann (ein bisschen) PyQt!", None)
# button=QPushButton(u"Hallo traumrose!\nIch liebe Dich!\nKüsst du mich?", None)

# Jetzt machen wir ihn zum Haupt-Widget 
# des Programmes "app", 
# so dass er auf der obersten Ebene liegt: 

app.setMainWidget(button)

# Dann sagen wir ihm, dass er angezeigt werden soll. 

button.show()

# Kurz vor dem Abschluss fügen wir noch 
# als kleine Spielerei 
# etwas Interaktivität hinzu: 
# Das Programm soll sich beenden, 
# wenn der Knopf gedrückt wird. 

# Dafür verbinden wir das Signal "pressed()" 
# des Knopfes "button" 
# mit dem Slot "quit()" des Programmes app. 

app.connect(button, SIGNAL("pressed()"), 
		app, SLOT("quit()"))

# Als letztes führen wir das GUI-Programm aus. 
# Erst hier wird der Knopf wirklich sichtbar. 

app.exec_loop()

# Um das zu testen kannst du das Programm einfach 
# Schritt für Schritt in der Python-Shell ausführen. 

# Das beendet mein erste Programm. 
# Ich hoffe, Du hattest Spaß beim Lesen!

Use Node:

⚙ Babcom is trying to load the comments ⚙

This textbox will disappear when the comments have been loaded.

If the box below shows an error-page, you need to install Freenet with the Sone-Plugin or set the node-path to your freenet node and click the Reload Comments button (or return).

If you see something like Invalid key: java.net.MalformedURLException: There is no @ in that URI! (Sone/search.html), you need to setup Sone and the Web of Trust

If you had Javascript enabled, you would see comments for this page instead of the Sone page of the sites author.

Note: To make a comment which isn’t a reply visible to others here, include a link to this site somewhere in the text of your comment. It will then show up here. To ensure that I get notified of your comment, also include my Sone-ID.

Link to this site and my Sone ID: sone://6~ZDYdvAgMoUfG6M5Kwi7SQqyS-gTcyFeaNN1Pf3FvY

This spam-resistant comment-field is made with babcom.

Inhalt abgleichen
Willkommen im Weltenwald!
((λ()'Dr.ArneBab))



Beliebte Inhalte

Draketo neu: Beiträge

Ein Würfel System

sn.1w6.org news