PySide Beginner Examples/de

Einführung
Der Zweck dieser Seite ist es, Beispiele auf Anfängerniveau für die PySide GUI Verwalter (es gibt begleitende Seiten Zwischen PySide Beispiele und Fortgeschrittene PySide Beispiele).

Neulinge in der GUI Programmierung könnten über das Wort "Widget" stolpern. Seine Bedeutung außerhalb der Computerwelt wird gewöhnlich wie folgt angegeben

"'eine kleine Spielerei oder mechanisches Gerät, insbesondere eines, dessen Name unbekannt oder unspezifiziert ist'"

For GUI work such as PySide the term "widget" is most often used to refer to the visible elements of the GUI - windows, dialogs, and input/output features. All visible elements of PySide are called widgets, and, for those who are interested, they all descend from a common parent class, QWidget. In addition to the visible elements PySide also offers widgets for networking, XML, multimedia, and database integration.

A widget that is not embedded in a parent widget is called a window and usually windows have a frame and a title bar. The most common types of windows are the "main window" (from the Class QMainWindow) and the various subclasses of the dialog (from the Class QDialog). One big difference is that QDialog is modal (i.e. the user can not do anything outside of the Dialog window while it is open) and the QMainWindow is non-modal which allows the user to interact with other windows in parallel.

This guide is a shortcut list for getting a PySide program working quickly under FreeCAD, it isn't intended to teach Python or PySide. Some sites that do that are:
 * PySide tutorial at zetcode.com
 * PySide/PyQt Tutorial at PythonCentral.io
 * PySide 1.0.7 Reference at Srinikom.github.io (note this is a reference, not a tutorial)

Import Anweisung
PySide is not loaded with Python by default, it must be requested prior to using it. The following command:

causes the 2 parts of PySide to be loaded - QtGui holds classes for managing the Graphic User Interface while QtCore contains classes that do not directly relate to management of the GUI (e.g. timers and geometry). Although it is possible to only import the one that is needed, generally they are both needed and both imported.

The import statements are not repeated in the snippets below; it is assumed that it is done at the beginning in each case.

Einfachstes Beispiel
Die einfachste Interaktion mit PySide besteht darin, dem Benutzer eine Nachricht zu präsentieren, die er nur akzeptieren kann:



Ja oder keine Abfrage
Die nächst einfachste Interaktion ist die Frage nach einer Ja/Nein Antwort: QtGui.QMessageBox.No, QtGui.QMessageBox.No) if reply == QtGui.QMessageBox.Yes:       # this is where the code relevant to a 'Yes' answer goes         pass if reply == QtGui.QMessageBox.No:         # this is where the code relevant to a 'No' answer goes         pass



Enter Text Query
The next code snippet asks the user for a piece of text - note this can be any key on the keyboard really:



Remember that even if the user enters only digits, "1234" for example, they are strings and must be converted to number representation with either of the following:

More Than 2 Buttons
The final Beginner Level example is of how to build a dialog with an arbitrary number of buttons. This example is programmatically too complex to be invoked from a single Python statement so in some ways it should be on the next page which is PySide Medium examples. But on the other hand this is often all that is needed without getting into complex GUI definitions, so the code is placed at the end of the page of this Beginner PySide page rather than the beginning of the following Medium PySide page.

Each piece of code under test would be in a function with the name 'routine1', 'routine2', etc. As many buttons as you can fit on the screen may be used. Follow the patterns in the code sample and add extra buttons as needed - the Dialog box will set it's width accordingly, up to the width of the screen.



Es gibt eine Codezeile:

was dazu führt, dass die Schaltflächen in einer horizontalen Linie liegen. Um sie in eine vertikale Linie zu setzen, ändere die zu lesende Zeile des Codes: