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/01 20:52] – [EAN check] roehner | en:examples [2022/08/25 21:28] (aktuell) – [EAN check] roehner | ||
---|---|---|---|
Zeile 1: | Zeile 1: | ||
- | ===== Exampes | + | ===== Examples |
==== EAN check ==== | ==== EAN check ==== | ||
+ | === Tkinter/TTK === | ||
- | The EAN check is an example of a simple GUI application. It has an entry component | + | The EAN check is an example of a simple GUI application. It has an entry widget |
{{en: | {{en: | ||
Zeile 11: | Zeile 12: | ||
def bCheck_Command(self): | def bCheck_Command(self): | ||
# Input | # Input | ||
- | EAN = self.eEANTV.get() | + | EAN = self.eEANCV.get() |
# 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 42: | Zeile 43: | ||
</ | </ | ||
- | According to the IPO principle, the input from the entry component | + | According to the IPO principle, the input from the entry widget |
<code python> | <code python> | ||
- | EAN = self.eEANTV.get() | + | EAN = self.eEANCV.get() |
</ | </ | ||
- | the EAN entered in the Entry component | + | the EAN entered in the Entry widget |
The processing part checks whether 13 digits have been entered and then performs the check digit calculation. | The processing part checks whether 13 digits have been entered and then performs the check digit calculation. | ||
- | Outputs are made to the text component labeled | + | Outputs are made to the text widget |
<code python> | <code python> | ||
Zeile 57: | Zeile 58: | ||
self.Output.insert(' | self.Output.insert(' | ||
</ | </ | ||
- | This inserts a line at the end of the text component | + | This inserts a line at the end of the text widget |
**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 72: | Zeile 89: | ||
{{en: | {{en: | ||
- | In the next step, the //car// class is used as a functional | + | In the next step, the //car// class is used as a functional |
{{en: | {{en: | ||
Zeile 84: | Zeile 101: | ||
</ | </ | ||
- | When refueling, the quantity entered in the entry component | + | === Tkinter/TKK === |
+ | |||
+ | When refueling, the quantity entered in the entry widget | ||
<code python> | <code python> | ||
def bRefuel_Command(self): | def bRefuel_Command(self): | ||
# Input from the GUI | # Input from the GUI | ||
- | amount = float(self.eAmountTV.get()) | + | amount = float(self.eAmountCV.get()) |
# Processing | # Processing | ||
self.car1.refuel(amount) | self.car1.refuel(amount) | ||
Zeile 96: | Zeile 115: | ||
</ | </ | ||
- | Then, according to the IPO principle, the entered amount is processed in the refuel() method. | + | Then, according to the IPO principle, the entered amount is processed in the //refuel()// method. |
- | Finally, the result is output with a separate method show(). The values for licenseplate, tank contents and mileage are retrieved via the get() methods of the class car and passed to the set() methods of the text variables | + | Finally, the result is output with a separate method |
<code python> | <code python> | ||
def show(self): | def show(self): | ||
- | self.eLicenseplateTV.set(self.car1.get_licenseplate()) | + | self.eLicenseplateCV.set(self.car1.get_licenseplate()) |
- | self.eTankcontentTV.set(self.car1.get_tankcontent()) | + | self.eTankcontentCV.set(self.car1.get_tankcontent()) |
- | self.eMileageTV.set(self.car1.get_mileage()) | + | self.eMileageCV.set(self.car1.get_mileage()) |
self.lCar.place(x = self.car1.get_mileage(), | self.lCar.place(x = self.car1.get_mileage(), | ||
</ | </ | ||
- | The label component | + | The label widget |
**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 127: | 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 145: | 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 178: | 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.1646164362.txt.gz · Zuletzt geändert: 2022/03/01 20:52 von roehner