en:examples
Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
Beide Seiten der vorigen RevisionVorhergehende ÜberarbeitungNächste Überarbeitung | Vorhergehende Überarbeitung | ||
en:examples [2022/03/04 17:16] – [Car] roehner | en:examples [2022/08/25 21:28] (aktuell) – [EAN check] roehner | ||
---|---|---|---|
Zeile 1: | Zeile 1: | ||
===== Examples ===== | ===== Examples ===== | ||
==== EAN check ==== | ==== EAN check ==== | ||
+ | === Tkinter/TTK === | ||
The EAN check is an example of a simple GUI application. It has an entry widget for entering an EAN and a text widget for the multi-line output of results. | The EAN check is an example of a simple GUI application. It has an entry widget for entering an EAN and a text widget for the multi-line output of results. | ||
Zeile 14: | Zeile 15: | ||
# Processing | # Processing | ||
if not EAN.isdigit(): | if not EAN.isdigit(): | ||
- | self.output(' | + | self.output(' |
if len(EAN) == 13: | if len(EAN) == 13: | ||
self.output(' | self.output(' | ||
Zeile 61: | Zeile 62: | ||
**Download**: | **Download**: | ||
*[[https:// | *[[https:// | ||
+ | |||
+ | === Qt variant of EAN check === | ||
+ | In Qt we have a LineEdit widget for input and a PlainTextWidget for output. To read the EAN we use the //text()// method of LineEdit widget. | ||
+ | |||
+ | <code python> | ||
+ | EAN = self.leEAN.text() | ||
+ | </ | ||
+ | |||
+ | The output is easier in Qt than in Tkinter/ | ||
+ | |||
+ | <code python> | ||
+ | def output(self, | ||
+ | self.Output.appendPlainText(line) | ||
+ | </ | ||
+ | | ||
+ | **Download**: | ||
+ | *[[https:// | ||
==== Car==== | ==== Car==== | ||
Zeile 82: | Zeile 100: | ||
self.car1 = car(' | self.car1 = car(' | ||
</ | </ | ||
+ | |||
+ | === Tkinter/TKK === | ||
When refueling, the quantity entered in the entry widget is read in via the get() method of the control variable // | When refueling, the quantity entered in the entry widget is read in via the get() method of the control variable // | ||
Zeile 111: | Zeile 131: | ||
**Download** | **Download** | ||
*[[https:// | *[[https:// | ||
+ | |||
+ | === Qt === | ||
+ | |||
+ | When refueling, the quantity is read in via the text() method of the LineEdit widget and converted into the required data type using //float//. | ||
+ | |||
+ | <code python> | ||
+ | def bRefuel_Command(self): | ||
+ | # Input from the GUI | ||
+ | amount = float(self.leAmount.text()) | ||
+ | # Processing | ||
+ | self.car1.refuel(amount) | ||
+ | # Output | ||
+ | self.show() | ||
+ | </ | ||
+ | |||
+ | Then, according to the IPO principle, the entered amount is processed in the // | ||
+ | |||
+ | Finally, the result is output with a separate method //show()//. The values for license plate, tank contents and mileage are retrieved via the get() methods of the class car and passed to the setText() methods of the widgets leLicenseplate, | ||
+ | |||
+ | <code python> | ||
+ | def show(self): | ||
+ | self.leLicenseplate.setText(self.car1.get_licenseplate()) | ||
+ | self.leTankcontent.setText(self.car1.get_tankcontent()) | ||
+ | self.leMileage.setText(self.car1.get_mileage()) | ||
+ | self.lCar.move(x = self.car1.get_mileage(), | ||
+ | </ | ||
+ | |||
+ | The label widget //lCar// has been assigned a car image via the //Pixmap// attribute in the object inspector. The //move()// method sets the x position of the car to the mileage. | ||
+ | |||
+ | **Download** | ||
+ | *[[https:// | ||
==== Linked List ==== | ==== Linked List ==== | ||
Zeile 126: | Zeile 177: | ||
</ | </ | ||
- | The implementation of an insert operation is difficult because four cases have to be distinguished: | + | The implementation of an insert operation is difficult because four cases must be distinguished: |
- The list is empty. | - The list is empty. | ||
- It should be inserted at the beginning. | - It should be inserted at the beginning. | ||
Zeile 144: | Zeile 195: | ||
{{en: | {{en: | ||
- | To insert at the end of the list, you have to use a loop and a cursor variable to navigate to the last element. The new node is added there. | + | To insert at the end of the list, you must use a loop and a cursor variable to navigate to the last element. The new node is added there. |
<code python> | <code python> | ||
Zeile 177: | Zeile 228: | ||
</ | </ | ||
- | Deleting a node is just as difficult, because the previous node has to be connected to the following one in order to delete it. | + | Deleting a node is just as difficult because the previous node must be connected to the following one in order to delete it. |
<code python> | <code python> |
en/examples.1646410563.txt.gz · Zuletzt geändert: 2022/03/04 17:16 von roehner