{"id":1732,"date":"2026-02-28T10:34:38","date_gmt":"2026-02-28T09:34:38","guid":{"rendered":"https:\/\/elv001.staging.360vier.net\/?p=1732"},"modified":"2026-04-30T17:05:41","modified_gmt":"2026-04-30T15:05:41","slug":"python-tkinter-gui-programmieren-einsteiger","status":"publish","type":"post","link":"https:\/\/de.elv.com\/elvjournal\/python-tkinter-gui-programmieren-einsteiger\/","title":{"rendered":"Einstieg in Python (Teil 10): Interaktiv mit Tkinter!"},"content":{"rendered":"\n<p class=\"has-gray-light-color has-text-color has-link-color has-h-5-font-size wp-elements-16a984fb387f88f98d8d58704eacdccd\"><strong>Einstieg in Python (Teil 10)<\/strong><\/p>\n\n\n\n<h1 class=\"wp-block-heading\">Interaktiv mit Tkinter!<\/h1>\n\n\n\n<p><strong>In den letzten Beitr\u00e4gen dieser Serie ging es \u00fcberwiegend um Datenausgaben, wie allgemeine Zahlenwerte, Sensordaten oder auch Lichtsignale von LEDs. Einer der wichtigsten Vorteile von Python ist jedoch, dass auch interaktive Steuerungen sehr leicht programmiert werden k\u00f6nnen.<\/strong> <strong>Hierf\u00fcr bietet sich die Tkinter-Bibliothek hervorragend an. Tkinter ist die standardm\u00e4\u00dfige Python-Bibliothek zur Erstellung grafischer Benutzeroberfl\u00e4chen (GUIs \u2013 \u201eGraphical User Interface\u201c).<\/strong> <strong>Mit Tkinter k\u00f6nnen Fenster, Buttons, Textfelder, Men\u00fcs und andere GUI-Elemente erstellt werden. Steuerungsaufgaben, vom einfachen Ein- und Ausschalten einer LED bis hin zu kompletten Heimautomatisierungen, k\u00f6nnen damit problemlos umgesetzt werden.<\/strong><\/p>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Flexible Steuerung \u00fcber Fenster<\/h2>\n\n\n\n<p>Die Tkinter-Bibliothek ist nach der Installation von Python \u00fcblicherweise vollst\u00e4ndig einsatzbereit. Im Bedarfsfall kann die Nachinstallation auf Systemen wie dem Raspberry Pi mit folgendem Befehl erfolgen:<\/p>\n\n\n\n<pre class=\"wp-block-code has-secondary-background-color has-background\" style=\"padding-top:var(--wp--preset--spacing--20);padding-right:var(--wp--preset--spacing--20);padding-bottom:var(--wp--preset--spacing--20);padding-left:var(--wp--preset--spacing--20)\"><code>sudo apt-get install python3-tk<\/code><\/pre>\n\n\n\n<p>Die ordnungsgem\u00e4\u00dfe Funktion wird mit einem kurzen Testprogramm \u00fcberpr\u00fcft:<\/p>\n\n\n\n<pre class=\"wp-block-code has-secondary-background-color has-background\" style=\"padding-top:var(--wp--preset--spacing--20);padding-right:var(--wp--preset--spacing--20);padding-bottom:var(--wp--preset--spacing--20);padding-left:var(--wp--preset--spacing--20)\"><code>import tkinter\ntkinter._test()<\/code><\/pre>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:66.66%\">\n<p>Die <code>_test<\/code>-Methode sorgt daf\u00fcr, dass ein eigenst\u00e4ndiges Fenster erzeugt wird <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-blue-color\">(Bild 1)<\/mark>. Innerhalb dieses Fensters finden sich verschiedene Elemente: Ein Textlabel, ein klickbarer Button \u201eClick me!\u201c, der bei jedem Klick seinen Text ver\u00e4ndert, und ein QUIT-Button, der die Anwendung schlie\u00dft. Dieses einfache Beispiel zeigt bereits die grundlegenden Bausteine einer Tkinter-Anwendung.<br>Bei jeder GUI wird zun\u00e4chst ein Hauptfenster erstellt. Dieses Fenster ist die Programmoberfl\u00e4che, die wie bei anderen Anwendungen vergr\u00f6\u00dfert, minimiert und geschlossen werden kann. Anschlie\u00dfend wird dieses Fenster mit interaktiven Elementen, den sogenannten \u201eWidgets\u201c, bef\u00fcllt.<\/p>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:33.33%\">\n<figure class=\"wp-block-image alignright size-full is-style-bordered\"><img loading=\"lazy\" decoding=\"async\" width=\"407\" height=\"338\" src=\"https:\/\/elvjournal.elv.com\/wp-content\/uploads\/page_2_img_1-2.jpg\" alt=\"Bild 1: Das Testfenster, das durch die Methode tkinter._test() erzeugt wird.\" class=\"wp-image-2819\" style=\"object-fit:cover\" srcset=\"https:\/\/elvjournal.elv.com\/wp-content\/uploads\/page_2_img_1-2.jpg 407w, https:\/\/elvjournal.elv.com\/wp-content\/uploads\/page_2_img_1-2-300x249.jpg 300w\" sizes=\"auto, (max-width: 407px) 100vw, 407px\" \/><figcaption class=\"wp-element-caption\">Bild 1: Das Testfenster, das durch die Methode tkinter._test() erzeugt wird.<\/figcaption><\/figure>\n<\/div>\n<\/div>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Die Python-Tkinter-Widgets<\/h2>\n\n\n\n<p>Steuerelemente wie Texte, Buttons oder Eingabefelder werden als \u201eWidgets\u201c bezeichnet. Der Text im Testfenster ist ein \u201eLabel\u201c, der \u201eClick me!\u201c-Button ist ein \u201eButton\u201c-Widget. Tkinter stellt zahlreiche weitere Widgets zur Verf\u00fcgung. Zuerst erzeugen wir mit <code>tkinter.Tk()<\/code> ein sogenanntes Tk-Objekt, welches das Hauptfenster der GUI darstellt. Die Referenz auf dieses Objekt speichern wir in einer Variablen, die \u00fcblicherweise <code>root<\/code> genannt wird:<\/p>\n\n\n\n<pre class=\"wp-block-code has-secondary-background-color has-background\" style=\"padding-top:var(--wp--preset--spacing--20);padding-right:var(--wp--preset--spacing--20);padding-bottom:var(--wp--preset--spacing--20);padding-left:var(--wp--preset--spacing--20)\"><code>root = tkinter.Tk()<\/code><\/pre>\n\n\n\n<p>Damit das Fenster tats\u00e4chlich erscheint, muss die sogenannte Tkinter-Event-Loop gestartet werden. Dies geschieht mit der <code>mainloop()<\/code>-Methode:<\/p>\n\n\n\n<pre class=\"wp-block-code has-secondary-background-color has-background\" style=\"padding-top:var(--wp--preset--spacing--20);padding-right:var(--wp--preset--spacing--20);padding-bottom:var(--wp--preset--spacing--20);padding-left:var(--wp--preset--spacing--20)\"><code>root.mainloop()<\/code><\/pre>\n\n\n\n<p>Nun erscheint ein leeres, aber bereits voll funktionsf\u00e4higes GUI-Fenster. Um den Text \u201eHello Python\u201c auszugeben, f\u00fcgen wir ein Label-Widget hinzu und positionieren es mit dem <code>pack<\/code>-Layout-Manager:<\/p>\n\n\n\n<pre class=\"wp-block-code has-secondary-background-color has-background\" style=\"padding-top:var(--wp--preset--spacing--20);padding-right:var(--wp--preset--spacing--20);padding-bottom:var(--wp--preset--spacing--20);padding-left:var(--wp--preset--spacing--20)\"><code>import tkinter\n\nroot = tkinter.Tk()\nlabel = tkinter.Label(root, text=\"Hello Python\")\nlabel.pack()\n\nroot.mainloop()<\/code><\/pre>\n\n\n\n<p>Der Layout-Manager <code>pack<\/code> sorgt daf\u00fcr, dass das Fenster gerade so gro\u00df ist, wie es der Inhalt erfordert. Das Label wird standardm\u00e4\u00dfig oben zentriert angezeigt <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-blue-color\">(Bild 2)<\/mark>.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized is-style-bordered\"><img loading=\"lazy\" decoding=\"async\" width=\"608\" height=\"137\" src=\"https:\/\/elvjournal.elv.com\/wp-content\/uploads\/page_2_img_2-2.jpg\" alt=\"Bild 2: Ein einfaches GUI-Fenster mit dem Text \u201eHello Python\u201c.\" class=\"wp-image-2818\" style=\"width:368px;height:auto\" srcset=\"https:\/\/elvjournal.elv.com\/wp-content\/uploads\/page_2_img_2-2.jpg 608w, https:\/\/elvjournal.elv.com\/wp-content\/uploads\/page_2_img_2-2-300x68.jpg 300w\" sizes=\"auto, (max-width: 608px) 100vw, 608px\" \/><figcaption class=\"wp-element-caption\">Bild 2: Ein einfaches GUI-Fenster mit dem Text \u201eHello Python\u201c.<\/figcaption><\/figure>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Die Fenstergr\u00f6\u00dfe und -position k\u00f6nnen mit der <code>geometry<\/code>-Methode angepasst werden. Auch ein Titel l\u00e4sst sich festlegen.<\/p>\n\n\n\n<pre class=\"wp-block-code has-secondary-background-color has-background\" style=\"padding-top:var(--wp--preset--spacing--20);padding-right:var(--wp--preset--spacing--20);padding-bottom:var(--wp--preset--spacing--20);padding-left:var(--wp--preset--spacing--20)\"><code>root.geometry(\"breite x h\u00f6he\" +x +y)<\/code><\/pre>\n\n\n\n<p>Widgets werden mit <code>pack<\/code> nacheinander horizontal oder vertikal gestapelt. Dies ist ideal f\u00fcr einfache Layouts. Wichtige Optionen hierf\u00fcr sind:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>side (z. B. tk.TOP, tk.BOTTOM, tk.LEFT, tk.RIGHT)<\/strong> f\u00fcr die Ausrichtung.<\/li>\n\n\n\n<li><strong>fill (z. B. tk.X, tk.Y, tk.BOTH):<\/strong> Bestimmt, ob das Widget den verf\u00fcgbaren Raum ausf\u00fcllt.<\/li>\n\n\n\n<li><strong>expand (True\/False):<\/strong> Gibt an, ob das Widget zus\u00e4tzlichen Raum nutzen soll.<\/li>\n<\/ul>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<p>Das folgende Programm (<code>stuctured_window.py<\/code>) demonstriert die Anwendung dieser Optionen und erzeugt die Ausgabe in <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-blue-color\">Bild 3<\/mark>.<\/p>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<figure class=\"wp-block-image size-full is-resized is-style-bordered\"><img loading=\"lazy\" decoding=\"async\" width=\"607\" height=\"224\" src=\"https:\/\/elvjournal.elv.com\/wp-content\/uploads\/page_3_img_1-3.jpg\" alt=\"Bild 3: Fensterlayout, das mit dem Pack-Manager und verschiedenen Ausrichtungs- und F\u00fclloptionen erstellt wurde.\" class=\"wp-image-2817\" style=\"width:503px;height:auto\" srcset=\"https:\/\/elvjournal.elv.com\/wp-content\/uploads\/page_3_img_1-3.jpg 607w, https:\/\/elvjournal.elv.com\/wp-content\/uploads\/page_3_img_1-3-300x111.jpg 300w\" sizes=\"auto, (max-width: 607px) 100vw, 607px\" \/><figcaption class=\"wp-element-caption\">Bild 3: Fensterlayout, das mit dem Pack-Manager und verschiedenen <br>Ausrichtungs- und F\u00fclloptionen erstellt wurde.<\/figcaption><\/figure>\n<\/div>\n<\/div>\n\n\n\n<pre class=\"wp-block-code has-secondary-background-color has-background\" style=\"padding-top:var(--wp--preset--spacing--20);padding-right:var(--wp--preset--spacing--20);padding-bottom:var(--wp--preset--spacing--20);padding-left:var(--wp--preset--spacing--20)\"><code>import tkinter as tk\n\nroot = tk.Tk()\nroot.title(\"Pack Beispiel mit Textfeldern\")\nroot.geometry(\"400x300\")\n\nentry1 = tk.Entry(root, bg=\"lightblue\")\nentry1.insert(0, \"Oben, keine F\u00fcllung\")\nentry1.pack(side=tk.TOP)\n\nentry2 = tk.Entry(root, bg=\"lightgreen\")\nentry2.insert(0, \"Unten, horizontal gef\u00fcllt\")\nentry2.pack(side=tk.BOTTOM, fill=tk.X)\n\nentry3 = tk.Entry(root, bg=\"lightyellow\")\nentry3.insert(0, \"Links, vertikal gef\u00fcllt\")\nentry3.pack(side=tk.LEFT, fill=tk.Y)\n\nentry4 = tk.Entry(root, bg=\"lightpink\")\nentry4.insert(0, \"Rechts, komplett gef\u00fcllt + expandiert\")\nentry4.pack(side=tk.RIGHT, fill=tk.BOTH, expand=True)\n\nroot.mainloop()<\/code><\/pre>\n\n\n\n<p>Zus\u00e4tzlich wurden verschiedene Hintergrundfarben (<code>bg<\/code> f\u00fcr background) festgelegt. Die Vordergrundfarbe (Textfarbe) kann entsprechend mit dem Parameter <code>fg<\/code> (foreground) angepasst werden. Ein Beispiel dazu findet sich im Download-Paket (<code>Colours.py<\/code>).<\/p>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Interaktive Steuerung: Ein digitaler Spielw\u00fcrfel<\/h2>\n\n\n\n<p>Eine beliebte Anwendung f\u00fcr Tkinter sind einfache Spiele. Als Anregung f\u00fcr eigene Entwicklungen dient hier ein softwarebasierter Spielw\u00fcrfel, der sein echtes Gegenst\u00fcck grafisch simuliert. Wir verwenden ein <code>Canvas<\/code>-Widget zur Darstellung der W\u00fcrfelaugen und einen Button, um eine Zufallszahl zwischen 1 und 6 zu \u201ew\u00fcrfeln\u201c.<\/p>\n\n\n\n<pre class=\"wp-block-code has-secondary-background-color has-background\" style=\"padding-top:var(--wp--preset--spacing--20);padding-right:var(--wp--preset--spacing--20);padding-bottom:var(--wp--preset--spacing--20);padding-left:var(--wp--preset--spacing--20)\"><code>import tkinter as tk\nimport random\n\n# Hauptfenster erstellen\nroot = tk.Tk()\nroot.title(\"W\u00fcrfelsimulation\")\nroot.geometry(\"300x400\")\n\n# Canvas f\u00fcr die W\u00fcrfelanzeige\ncanvas = tk.Canvas(root, width=200, height=200, bg=\"white\")\ncanvas.pack(pady=50)\n\n# Funktion zum Zeichnen der W\u00fcrfelpunkte\ndef draw_dice(number):\n    canvas.delete(\"all\")\n    # Vorherige Punkte l\u00f6schen\n    canvas.create_rectangle(10, 10, 190, 190, outline=\"black\", width=2)\n    # W\u00fcrfelrahmen\n    # Positionen der Punkte (Mitte = 100, 100)\n    positions = {\n        1: &#91;(100, 100)],  # Mitte\n        2: &#91;(50, 50), (150, 150)],  # Diagonale\n        3: &#91;(50, 50), (100, 100), (150, 150)],  # Diagonale + Mitte\n        4: &#91;(50, 50), (50, 150), (150, 50), (150, 150)],  # Ecken\n        5: &#91;(50, 50), (50, 150), (150, 50), (150, 150), (100, 100)],  # Ecken + Mitte\n        6: &#91;(50, 50), (50, 100), (50, 150), (150, 50), (150, 100), (150, 150)]  # 3x3 ohne Mitte\n    }\n    # Punkte zeichnen\n    for pos in positions&#91;number]:\n        x, y = pos\n        canvas.create_oval(x - 10, y - 10, x + 10, y + 10, fill=\"black\")\n\n# Funktion zum W\u00fcrfeln\ndef roll_dice():\n    number = random.randint(1, 6)  # Zuf\u00e4llige Zahl von 1 bis 6\n    draw_dice(number)  # W\u00fcrfel neu zeichnen\n    result_label.config(text=f\"Gew\u00fcrfelt: {number}\")  # Ergebnis anzeigen\n\n# Button zum W\u00fcrfeln\nroll_button = tk.Button(root, text=\"W\u00fcrfeln!\", command=roll_dice, font=(\"Arial\", 14), bg=\"lightgreen\")\nroll_button.pack(pady=20)\n\n# Label f\u00fcr das Ergebnis\nresult_label = tk.Label(root, text=\"Gew\u00fcrfelt: -\", font=(\"Arial\", 12))\nresult_label.pack(pady=10)\n\n# Initialen W\u00fcrfel zeichnen (z. B. 1)\ndraw_dice(1)\n\n# Hauptschleife starten\nroot.mainloop()<\/code><\/pre>\n\n\n\n<p>Im Programm wird ein Fenster erstellt, in dem ein <code>Canvas<\/code> als Zeichenfl\u00e4che dient. Die Positionen der W\u00fcrfelpunkte sind f\u00fcr jede Zahl von 1 bis 6 vordefiniert:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>1:<\/strong> ein Punkt in der Mitte<\/li>\n\n\n\n<li><strong>2:<\/strong> zwei Punkte diagonal gegen\u00fcber<\/li>\n\n\n\n<li><strong>3:<\/strong> drei Punkte diagonal inklusive Mitte<\/li>\n\n\n\n<li><strong>4:<\/strong> vier Punkte in den Ecken<\/li>\n\n\n\n<li><strong>5:<\/strong> vier Ecken plus Mitte<\/li>\n\n\n\n<li><strong>6:<\/strong> sechs Punkte in zwei Reihen<\/li>\n<\/ul>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:66.66%\">\n<p>Die Funktion <code>roll_dice<\/code> erzeugt eine Zufallszahl und ruft <code>draw_dice<\/code> auf, um den W\u00fcrfel neu zu zeichnen. Ein Button l\u00f6st diesen Vorgang aus, und ein Label zeigt das Ergebnis an <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-blue-color\">(Bild 4)<\/mark>.<\/p>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:33.33%\">\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"327\" height=\"459\" src=\"https:\/\/elvjournal.elv.com\/wp-content\/uploads\/page_3_img_2.jpg\" alt=\"Bild 4: Grafische Simulation eines Spielw\u00fcrfels mit Tkinter.\" class=\"wp-image-2816\" srcset=\"https:\/\/elvjournal.elv.com\/wp-content\/uploads\/page_3_img_2.jpg 327w, https:\/\/elvjournal.elv.com\/wp-content\/uploads\/page_3_img_2-214x300.jpg 214w\" sizes=\"auto, (max-width: 327px) 100vw, 327px\" \/><figcaption class=\"wp-element-caption\">Bild 4: Grafische Simulation eines Spielw\u00fcrfels mit Tkinter.<\/figcaption><\/figure>\n<\/div>\n<\/div>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Raspberry Pi als Taschenrechner<\/h2>\n\n\n\n<p>Dass man mit Tkinter auch ernsthaftere Anwendungen programmieren kann, zeigt das folgende Beispiel: ein voll funktionsf\u00e4higer Taschenrechner als grafische Emulation (<code>Calculator.py<\/code>).<\/p>\n\n\n\n<pre class=\"wp-block-code has-secondary-background-color has-background\" style=\"padding-top:var(--wp--preset--spacing--20);padding-right:var(--wp--preset--spacing--20);padding-bottom:var(--wp--preset--spacing--20);padding-left:var(--wp--preset--spacing--20)\"><code>import tkinter as tk\n\ndef calculate():\n    try:\n        expression = entry.get()\n        result = eval(expression)\n        entry.delete(0, tk.END)\n        entry.insert(tk.END, str(result))\n    except Exception as e:\n        entry.delete(0, tk.END)\n        entry.insert(tk.END, \"Error\")\n\ndef clear():\n    entry.delete(0, tk.END)\n\nroot = tk.Tk()\nroot.title(\"Einfacher Taschenrechner\")\n\nentry = tk.Entry(root, width=30, borderwidth=5)\nentry.grid(row=0, column=0, columnspan=4, padx=10, pady=10)\n\nbuttons = &#91;\n    \"7\", \"8\", \"9\", \"\/\",\n    \"4\", \"5\", \"6\", \"*\",\n    \"1\", \"2\", \"3\", \"-\",\n    \"0\", \".\", \"=\", \"+\"\n]\n\nrow_val = 1\ncol_val = 0\n\nfor button in buttons:\n    command = lambda b=button: calculate() if b == \"=\" else entry.insert(tk.END, b)\n    tk.Button(root, text=button, padx=20, pady=20, command=command).grid(row=row_val, column=col_val)\n    col_val += 1\n    if col_val &gt; 3:\n        col_val = 0\n        row_val += 1\n\ntk.Button(root, text=\"C\", padx=20, pady=20, command=clear).grid(row=row_val, column=col_val)\n\nroot.mainloop()<\/code><\/pre>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:66.66%\">\n<p>Die Funktion <code>calculate<\/code> liest den Ausdruck aus dem Eingabefeld, wertet ihn mit <code>eval()<\/code> aus und zeigt das Ergebnis an. Die Tasten werden in einem Raster (Grid) platziert. Je nach gedr\u00fcckter Taste wird der Wert in das Eingabefeld eingef\u00fcgt, die Berechnung ausgel\u00f6st oder das Feld gel\u00f6scht. <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-blue-color\">Bild 5<\/mark> zeigt den fertigen Taschenrechner.<\/p>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:33.33%\">\n<figure class=\"wp-block-image size-full is-style-bordered\"><img loading=\"lazy\" decoding=\"async\" width=\"383\" height=\"672\" src=\"https:\/\/elvjournal.elv.com\/wp-content\/uploads\/page_5_img_1-2.jpg\" alt=\"Bild 5: Ein voll funktionsf\u00e4higer Taschenrechner, erstellt mit der Tkinter-Bibliothek.\" class=\"wp-image-2815\" srcset=\"https:\/\/elvjournal.elv.com\/wp-content\/uploads\/page_5_img_1-2.jpg 383w, https:\/\/elvjournal.elv.com\/wp-content\/uploads\/page_5_img_1-2-171x300.jpg 171w\" sizes=\"auto, (max-width: 383px) 100vw, 383px\" \/><figcaption class=\"wp-element-caption\">Bild 5: Ein voll funktionsf\u00e4higer Taschenrechner, erstellt mit der Tkinter-Bibliothek.<\/figcaption><\/figure>\n<\/div>\n<\/div>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Dynamische Grafiken und Uhren<\/h2>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<p>Mit Tkinter lassen sich auch dynamische, sich selbstst\u00e4ndig aktualisierende Grafiken umsetzen. Ein sch\u00f6nes Beispiel hierf\u00fcr ist eine programmierte Analoguhr, die einer klassischen Bahnhofsuhr nachempfunden ist <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-blue-color\">(Bild 6)<\/mark>.<\/p>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<figure class=\"wp-block-image alignright size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"461\" height=\"485\" src=\"https:\/\/elvjournal.elv.com\/wp-content\/uploads\/page_6_img_1.jpg\" alt=\"Bild 6: Eine quasi-analoge Uhr, dynamisch aktualisiert mit Tkinter und dem time-Modul.\" class=\"wp-image-2814\" srcset=\"https:\/\/elvjournal.elv.com\/wp-content\/uploads\/page_6_img_1.jpg 461w, https:\/\/elvjournal.elv.com\/wp-content\/uploads\/page_6_img_1-285x300.jpg 285w\" sizes=\"auto, (max-width: 461px) 100vw, 461px\" \/><figcaption class=\"wp-element-caption\">Bild 6: Eine quasi-analoge Uhr, dynamisch aktualisiert mit Tkinter und dem time-Modul.<\/figcaption><\/figure>\n<\/div>\n<\/div>\n\n\n\n<pre class=\"wp-block-code has-secondary-background-color has-background\" style=\"padding-top:var(--wp--preset--spacing--20);padding-right:var(--wp--preset--spacing--20);padding-bottom:var(--wp--preset--spacing--20);padding-left:var(--wp--preset--spacing--20)\"><code>import tkinter as tk\nfrom math import sin, cos, radians\nimport time\n\nclass AnalogClock:\n    def __init__(self, root):\n        self.root = root\n        self.root.title(\"Analog Clock\")\n        self.canvas = tk.Canvas(root, width=400, height=400, bg='white')\n        self.canvas.pack()\n        self.MX = 200\n        self.MY = 200\n        self.R = 190\n        self.draw_clock_face()\n        self.s1 = -1\n        self.update_clock()\n\n    def draw_clock_face(self):\n        for i in range(60):\n            x, y = self.get_point(self.R, i)\n            size = 4 if i % 5 == 0 else 2\n            self.canvas.create_oval(x - size, y - size, x + size, y + size, fill='black')\n\n    def get_point(self, length, angle):\n        w1 = radians(angle * 6 - 90)\n        x1 = self.MX + length * cos(w1)\n        y1 = self.MY + length * sin(w1)\n        return (x1, y1)\n\n    def update_clock(self):\n        zeit = time.localtime()\n        s = zeit.tm_sec\n        m = zeit.tm_min\n        h = zeit.tm_hour\n\n        if h &gt; 12:\n            h = h - 12\n        hm = (h + m \/ 60.0) * 5\n\n        if s != self.s1:\n            self.canvas.delete(\"hands\")\n            x, y = self.get_point(120, hm)\n            self.canvas.create_line(self.MX, self.MY, x, y, width=6, fill='black', tags=\"hands\")\n            x, y = self.get_point(170, m)\n            self.canvas.create_line(self.MX, self.MY, x, y, width=4, fill='black', tags=\"hands\")\n            x, y = self.get_point(180, s)\n            self.canvas.create_line(self.MX, self.MY, x, y, width=2, fill='red', tags=\"hands\")\n\n            self.s1 = s\n        self.root.title(\"Aktuelle Zeit: \" + time.asctime())\n        self.root.after(1000, self.update_clock)\n\nroot = tk.Tk()\nclock = AnalogClock(root)\nroot.bind('&lt;Escape&gt;', lambda e: root.quit())\nroot.mainloop()<\/code><\/pre>\n\n\n\n<p>Die Uhr wird auf einem 400&#215;400 Pixel gro\u00dfen Canvas gezeichnet. Zun\u00e4chst wird das Zifferblatt mit Markierungen f\u00fcr Minuten und Stunden erstellt. Die Positionen werden mit trigonometrischen Funktionen berechnet. Die Zeiger f\u00fcr Stunde, Minute und Sekunde werden jede Sekunde neu gezeichnet, um die aktuelle Zeit anzuzeigen. Sie unterscheiden sich in L\u00e4nge, Dicke und Farbe, um gut lesbar zu sein:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Stundenzeiger:<\/strong> kurz, dick und schwarz.<\/li>\n\n\n\n<li><strong>Minutenzeiger:<\/strong> mittellang, mitteldick und schwarz.<\/li>\n\n\n\n<li><strong>Sekundenzeiger:<\/strong> lang, d\u00fcnn und rot.<\/li>\n<\/ul>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Aktive Hardwaresteuerung per GUI<\/h2>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<p>Eine der wichtigsten Anwendungen von Tkinter ist die Steuerung von Hardware. Um beispielsweise eine LED am Raspberry Pi zu schalten, kombinieren wir eine Tkinter-GUI mit der GPIO-Schnittstelle <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-blue-color\">(Bild 7)<\/mark>. Die LED wird an GPIO 17 angeschlossen, und \u00fcber Buttons in der GUI wird sie ein- oder ausgeschaltet.<\/p>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<figure class=\"wp-block-image size-full is-resized is-style-bordered\"><img loading=\"lazy\" decoding=\"async\" width=\"816\" height=\"604\" src=\"https:\/\/elvjournal.elv.com\/wp-content\/uploads\/page_7_img_1.jpg\" alt=\"Bild 7: Schaltungsaufbau zur Steuerung eines LED-Moduls am Raspberry Pi.\" class=\"wp-image-2813\" style=\"width:657px;height:auto\" srcset=\"https:\/\/elvjournal.elv.com\/wp-content\/uploads\/page_7_img_1.jpg 816w, https:\/\/elvjournal.elv.com\/wp-content\/uploads\/page_7_img_1-300x222.jpg 300w, https:\/\/elvjournal.elv.com\/wp-content\/uploads\/page_7_img_1-768x568.jpg 768w\" sizes=\"auto, (max-width: 816px) 100vw, 816px\" \/><figcaption class=\"wp-element-caption\">Bild 7: Schaltungsaufbau zur Steuerung eines LED-Moduls am Raspberry Pi.<\/figcaption><\/figure>\n<\/div>\n<\/div>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<p>Das Programm (<code>LEDcontrol.py<\/code>) initialisiert den GPIO-Pin als Ausgang und erstellt ein Fenster mit zwei Buttons (\u201eLED an\u201c und \u201eLED aus\u201c) sowie einem Statuslabel <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-blue-color\">(Bild 8)<\/mark>.<\/p>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<figure class=\"wp-block-image size-full is-style-bordered\"><img loading=\"lazy\" decoding=\"async\" width=\"602\" height=\"421\" src=\"https:\/\/elvjournal.elv.com\/wp-content\/uploads\/page_8_img_1.jpg\" alt=\"Bild 8: Das Steuerungsfenster f\u00fcr die LED.\" class=\"wp-image-2812\" srcset=\"https:\/\/elvjournal.elv.com\/wp-content\/uploads\/page_8_img_1.jpg 602w, https:\/\/elvjournal.elv.com\/wp-content\/uploads\/page_8_img_1-300x210.jpg 300w\" sizes=\"auto, (max-width: 602px) 100vw, 602px\" \/><figcaption class=\"wp-element-caption\">Bild 8: Das Steuerungsfenster f\u00fcr die LED.<\/figcaption><\/figure>\n<\/div>\n<\/div>\n\n\n\n<pre class=\"wp-block-code has-secondary-background-color has-background\" style=\"padding-top:var(--wp--preset--spacing--20);padding-right:var(--wp--preset--spacing--20);padding-bottom:var(--wp--preset--spacing--20);padding-left:var(--wp--preset--spacing--20)\"><code>import tkinter as tk\nimport RPi.GPIO as GPIO\n\nLED_PIN = 17\nGPIO.setmode(GPIO.BCM)\nGPIO.setup(LED_PIN, GPIO.OUT)\nGPIO.output(LED_PIN, GPIO.LOW)\n\ndef led_an():\n    GPIO.output(LED_PIN, GPIO.HIGH)\n    status_label.config(text=\"LED ist AN\")\n\ndef led_aus():\n    GPIO.output(LED_PIN, GPIO.LOW)\n    status_label.config(text=\"LED ist AUS\")\n\nroot = tk.Tk()\nroot.title(\"LED-Steuerung\")\nroot.geometry(\"300x200\")\n\nstatus_label = tk.Label(root, text=\"LED ist AUS\", font=(\"Arial\", 14))\nstatus_label.pack(pady=20)\n\nan_button = tk.Button(root, text=\"LED an\", command=led_an, bg=\"lightgreen\", font=(\"Arial\", 12))\nan_button.pack(pady=10)\n\naus_button = tk.Button(root, text=\"LED aus\", command=led_aus, bg=\"lightcoral\", font=(\"Arial\", 12))\naus_button.pack(pady=10)\n\ndef cleanup():\n    GPIO.cleanup()\n    root.destroy()\n\nroot.protocol(\"WM_DELETE_WINDOW\", cleanup)\nroot.mainloop()<\/code><\/pre>\n\n\n\n<p>Die Funktionen <code>led_an()<\/code> und <code>led_aus()<\/code> setzen den GPIO-Pin auf HIGH bzw. LOW und aktualisieren den Text im Statuslabel. Wichtig ist die <code>cleanup()<\/code>-Funktion, die beim Schlie\u00dfen des Fensters aufgerufen wird, um die GPIO-Pins sicher zur\u00fcckzusetzen.<\/p>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Automatisierung im Griff: Motorsteuerung<\/h2>\n\n\n\n<p>Um die Drehzahl eines kleinen DC-Motors zu steuern, erstellen wir eine GUI mit einem Schieberegler (\u201eSlider\u201c). Die Hardwarebasis bildet ein Raspberry Pi, der den Motor \u00fcber eine Transistorstufe ansteuert, da der Motor mehr Strom ben\u00f6tigt, als ein GPIO-Pin direkt liefern kann. Die Drehzahl wird mittels Pulsweitenmodulation (PWM) geregelt.<\/p>\n\n\n\n<pre class=\"wp-block-code has-secondary-background-color has-background\" style=\"padding-top:var(--wp--preset--spacing--20);padding-right:var(--wp--preset--spacing--20);padding-bottom:var(--wp--preset--spacing--20);padding-left:var(--wp--preset--spacing--20)\"><code>import tkinter as tk\nfrom tkinter import ttk\nimport RPi.GPIO as GPIO\n\n# GPIO-Setup\nMOTOR_PIN = 17  # GPIO-Pin f\u00fcr den Motor\nGPIO.setmode(GPIO.BCM)  # BCM-Nummerierung\nGPIO.setup(MOTOR_PIN, GPIO.OUT)  # Pin als Ausgang\npwm = GPIO.PWM(MOTOR_PIN, 100)  # PWM mit 100 Hz Frequenz\npwm.start(0)  # Start mit 0 % Duty Cycle (Motor aus)\n\n# Funktion zur Drehzahlsteuerung\ndef update_drehzahl(value):\n    duty_cycle = float(value)  # Wert von 0 bis 100\n    pwm.ChangeDutyCycle(duty_cycle)  # PWM anpassen\n    status_label.config(text=f\"Drehzahl: {int(duty_cycle)}%\")\n\n# GUI erstellen\nroot = tk.Tk()\nroot.title(\"DC-Motor Drehzahlsteuerung\")\nroot.geometry(\"300x200\")\n\nstatus_label = tk.Label(root, text=\"Drehzahl: 0%\", font=(\"Arial\", 14))\nstatus_label.pack(pady=10)\n\n# Rahmen f\u00fcr Schieberegler und Werte\nframe = tk.Frame(root)\nframe.pack(pady=10, padx=20, fill=\"x\")\n\n# Label f\u00fcr 0\nlabel_min = tk.Label(frame, text=\"0\", font=(\"Arial\", 12))\nlabel_min.pack(side=\"left\")\n\n# Schieberegler f\u00fcr Drehzahl (0 bis 100)\nslider = ttk.Scale(frame, from_=0, to=100, orient=\"horizontal\", command=update_drehzahl)\nslider.pack(side=\"left\", expand=True, fill=\"x\")\n\n# Label f\u00fcr 100\nlabel_max = tk.Label(frame, text=\"100\", font=(\"Arial\", 12))\nlabel_max.pack(side=\"right\")\n\n# Cleanup beim Schlie\u00dfen\ndef cleanup():\n    pwm.stop()  # PWM beenden\n    GPIO.cleanup()  # GPIO aufr\u00e4umen\n    root.destroy()  # Fenster schlie\u00dfen\n\nroot.protocol(\"WM_DELETE_WINDOW\", cleanup)\n\n# Hauptschleife starten\nroot.mainloop()<\/code><\/pre>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<p>Die Funktion <code>update_drehzahl<\/code> wird bei jeder \u00c4nderung des Schiebereglers aufgerufen und passt den Duty Cycle des PWM-Signals an. Dadurch \u00e4ndert sich die Motorgeschwindigkeit <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-blue-color\">(Bild 9)<\/mark>. F\u00fcr einen sicheren Betrieb ist eine externe Spannungsquelle f\u00fcr den Motor empfehlenswert, um den Raspberry Pi vor \u00dcberlastung und Spannungsspitzen zu sch\u00fctzen <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-blue-color\">(Bild 10 + Bild 11 + Bild 12)<\/mark>.<\/p>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<figure class=\"wp-block-image size-full is-style-bordered\"><img loading=\"lazy\" decoding=\"async\" width=\"603\" height=\"222\" src=\"https:\/\/elvjournal.elv.com\/wp-content\/uploads\/page_9_img_1.jpg\" alt=\"Bild 9: GUI zur Steuerung der Motordrehzahl \u00fcber einen Schieberegler.\" class=\"wp-image-2811\" srcset=\"https:\/\/elvjournal.elv.com\/wp-content\/uploads\/page_9_img_1.jpg 603w, https:\/\/elvjournal.elv.com\/wp-content\/uploads\/page_9_img_1-300x110.jpg 300w\" sizes=\"auto, (max-width: 603px) 100vw, 603px\" \/><figcaption class=\"wp-element-caption\">Bild 9: GUI zur Steuerung der Motordrehzahl \u00fcber einen Schieberegler.<\/figcaption><\/figure>\n<\/div>\n<\/div>\n\n\n\n<div class=\"wp-block-columns are-vertically-aligned-bottom is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-vertically-aligned-bottom is-layout-flow wp-block-column-is-layout-flow\">\n<figure class=\"wp-block-image size-full is-resized is-style-bordered\"><img loading=\"lazy\" decoding=\"async\" width=\"882\" height=\"570\" src=\"https:\/\/elvjournal.elv.com\/wp-content\/uploads\/page_10_img_2.jpg\" alt=\"Bild 10: Schaltung mit Freilaufdiode zum Schutz vor Spannungsspitzen.\" class=\"wp-image-2810\" style=\"width:634px;height:auto\" srcset=\"https:\/\/elvjournal.elv.com\/wp-content\/uploads\/page_10_img_2.jpg 882w, https:\/\/elvjournal.elv.com\/wp-content\/uploads\/page_10_img_2-300x194.jpg 300w, https:\/\/elvjournal.elv.com\/wp-content\/uploads\/page_10_img_2-768x496.jpg 768w\" sizes=\"auto, (max-width: 882px) 100vw, 882px\" \/><figcaption class=\"wp-element-caption\">Bild 10: Schaltung mit Freilaufdiode zum Schutz vor Spannungsspitzen.<\/figcaption><\/figure>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-vertically-aligned-bottom is-layout-flow wp-block-column-is-layout-flow\">\n<figure class=\"wp-block-image size-full is-resized is-style-bordered\"><img loading=\"lazy\" decoding=\"async\" width=\"881\" height=\"626\" src=\"https:\/\/elvjournal.elv.com\/wp-content\/uploads\/page_10_img_3.jpg\" alt=\"Bild 11: Oszilloskop-Ansicht des PWM-Signals bei mittlerer Leistung.\" class=\"wp-image-2809\" style=\"width:485px;height:auto\" srcset=\"https:\/\/elvjournal.elv.com\/wp-content\/uploads\/page_10_img_3.jpg 881w, https:\/\/elvjournal.elv.com\/wp-content\/uploads\/page_10_img_3-300x213.jpg 300w, https:\/\/elvjournal.elv.com\/wp-content\/uploads\/page_10_img_3-768x546.jpg 768w\" sizes=\"auto, (max-width: 881px) 100vw, 881px\" \/><figcaption class=\"wp-element-caption\">Bild 11: Oszilloskop-Ansicht des PWM-Signals bei mittlerer Leistung.<\/figcaption><\/figure>\n<\/div>\n<\/div>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\"><\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<figure class=\"wp-block-image size-full is-resized is-style-bordered\"><img loading=\"lazy\" decoding=\"async\" width=\"882\" height=\"615\" src=\"https:\/\/elvjournal.elv.com\/wp-content\/uploads\/page_10_img_1.jpg\" alt=\"Bild 12: Aufbauvorschlag f\u00fcr die Motorsteuerung mit externer Spannungsquelle.\" class=\"wp-image-2808\" style=\"width:488px;height:auto\" srcset=\"https:\/\/elvjournal.elv.com\/wp-content\/uploads\/page_10_img_1.jpg 882w, https:\/\/elvjournal.elv.com\/wp-content\/uploads\/page_10_img_1-300x209.jpg 300w, https:\/\/elvjournal.elv.com\/wp-content\/uploads\/page_10_img_1-768x536.jpg 768w\" sizes=\"auto, (max-width: 882px) 100vw, 882px\" \/><figcaption class=\"wp-element-caption\">Bild 12: Aufbauvorschlag f\u00fcr die Motorsteuerung mit externer Spannungsquelle.<\/figcaption><\/figure>\n<\/div>\n<\/div>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<div class=\"wp-block-group has-gray-lightest-100-background-color has-background is-layout-constrained wp-container-core-group-is-layout-ff778368 wp-block-group-is-layout-constrained\" style=\"padding-right:var(--wp--preset--spacing--30);padding-left:var(--wp--preset--spacing--30)\">\n<h2 class=\"wp-block-heading\">Erg\u00e4nzungen und \u00dcbungen<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Erweiterungsideen zum Spielw\u00fcrfel<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Animation:<\/strong> Wie k\u00f6nnte man eine kurze Animation (z. B. schnelles Wechseln der Augenzahlen) einsetzen, um den W\u00fcrfel vor dem endg\u00fcltigen Ergebnis \u201erollen\u201c zu lassen?<\/li>\n\n\n\n<li><strong>Farben:<\/strong> Gestalten Sie den W\u00fcrfelrahmen oder die Punkte farbig.<\/li>\n\n\n\n<li><strong>Gr\u00f6\u00dfe:<\/strong> Wie l\u00e4sst sich die Gr\u00f6\u00dfe des W\u00fcrfels dynamisch anpassen?<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Erweiterungsideen zum Taschenrechner<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Wie k\u00f6nnten wissenschaftliche Funktionen (Sinus, Cosinus, etc.) eingebaut werden?<\/li>\n\n\n\n<li>Wie kann man den Taschenrechner um grafische Funktionen, z.B. einen Funktionsplotter, erweitern?<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Erweiterungsideen zur Motorsteuerung<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Was ist zu beachten, wenn man leistungsst\u00e4rkere Motoren betreiben will?<\/li>\n\n\n\n<li>Wie k\u00f6nnte man die Steuerung um einen Vorw\u00e4rts- und R\u00fcckw\u00e4rtslauf erweitern (z.B. mit einer H-Br\u00fccke)?<\/li>\n<\/ul>\n<\/div>\n\n\n\n<div style=\"height:40px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Zusammenfassung und Ausblick<\/h2>\n\n\n\n<p>In diesem Artikel haben Sie die Grundlagen der interaktiven grafischen Programmierung mit Tkinter kennengelernt. Von einfachen Softwareanwendungen wie Uhren und Taschenrechnern bis hin zur Hardwaresteuerung f\u00fcr LEDs oder DC-Motoren sind die M\u00f6glichkeiten vielf\u00e4ltig. Im n\u00e4chsten Beitrag werden wir uns fortgeschrittenere Anwendungen ansehen, insbesondere die Darstellung von analogen Messwerten \u00fcber virtuelle Messinstrumente. Dies \u00f6ffnet die T\u00fcr zu Projekten wie Wetterstationen, Motor\u00fcberwachung im Kfz-Bereich oder komplexen Hausautomatisierungen.<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Material<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Raspberry Pi mit Netzteil<\/li>\n\n\n\n<li>Breadboard und Jumperkabel<\/li>\n\n\n\n<li>LED mit Vorwiderstand oder LED-Modul<\/li>\n\n\n\n<li>Kleiner DC-Motor<\/li>\n\n\n\n<li>NPN-Transistor oder Transistormodul<\/li>\n\n\n\n<li>Diode und Widerstand<\/li>\n<\/ul>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"has-gray-lightest-100-background-color has-background\" style=\"padding-top:var(--wp--preset--spacing--20);padding-right:var(--wp--preset--spacing--20);padding-bottom:var(--wp--preset--spacing--20);padding-left:var(--wp--preset--spacing--20)\"><strong>\u00dcber den Autor<br><\/strong>Dr. G\u00fcnter Spanner ist als Autor zu den Themen Elektronik, Sensortechnik und Mikrocontroller einem weiten Fachpublikum bekannt. Schwerpunkt seiner hauptberuflichen T\u00e4tigkeit f\u00fcr verschiedene Gro\u00dfkonzerne wie Siemens und ABB ist die Projektleitung im Bereich Entwicklung und Technologie-Management. Der Dozent fu\u0308r Physik und Elektrotechnik hat zudem zahlreiche Fachartikel und Bu\u0308cher vero\u0308ffentlicht sowie Kurse und Lernpakete erstellt.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Interaktiv mit Tkinter: Lerne, wie du in Python grafische Oberfl\u00e4chen erstellst \u2013 von einfachen Labels und Layouts bis zu Projekten wie Spielw\u00fcrfel, Taschenrechner, Analoguhr sowie LED- und Motorsteuerung auf dem Raspberry Pi. Perfekt f\u00fcr deinen Einstieg in GUIs und Automation.<\/p>\n","protected":false},"author":7,"featured_media":864,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[34],"tags":[229,228,232,234,231,235,230,233],"post-author":[137],"class_list":["post-1732","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python-micropython","tag-micropython-tkinter","tag-python-gui-beispiele","tag-python-gui-einsteiger","tag-python-gui-programmieren","tag-python-tkinter","tag-python-tkinter-raspberry-pi","tag-tkinter-buttons-fenster","tag-tkinter-tutorial","post-author-dr-guenter-spanner"],"acf":[],"info":{"thumbnail":{"url":"https:\/\/elvjournal.elv.com\/wp-content\/uploads\/header_phyton_teil11.jpg","alt":""},"teaserImage":{"ID":2330,"id":2330,"title":"liste-beitrag_python_t10","filename":"Liste-Beitrag_python_t10.jpg","filesize":57591,"url":"https:\/\/elvjournal.elv.com\/wp-content\/uploads\/Liste-Beitrag_python_t10.jpg","link":"https:\/\/de.elv.com\/elvjournal\/python-tkinter-gui-programmieren-einsteiger\/liste-beitrag_python_t10\/","alt":"","author":"5","description":"","caption":"","name":"liste-beitrag_python_t10","status":"inherit","uploaded_to":1732,"date":"2025-09-04 12:48:31","modified":"2025-09-04 12:48:31","menu_order":0,"mime_type":"image\/jpeg","type":"image","subtype":"jpeg","icon":"https:\/\/elvjournal.elv.com\/wp-includes\/images\/media\/default.png","width":312,"height":198,"sizes":{"thumbnail":"https:\/\/elvjournal.elv.com\/wp-content\/uploads\/Liste-Beitrag_python_t10-250x198.jpg","thumbnail-width":250,"thumbnail-height":198,"medium":"https:\/\/elvjournal.elv.com\/wp-content\/uploads\/Liste-Beitrag_python_t10-300x190.jpg","medium-width":300,"medium-height":190,"medium_large":"https:\/\/elvjournal.elv.com\/wp-content\/uploads\/Liste-Beitrag_python_t10.jpg","medium_large-width":312,"medium_large-height":198,"large":"https:\/\/elvjournal.elv.com\/wp-content\/uploads\/Liste-Beitrag_python_t10.jpg","large-width":312,"large-height":198,"1536x1536":"https:\/\/elvjournal.elv.com\/wp-content\/uploads\/Liste-Beitrag_python_t10.jpg","1536x1536-width":312,"1536x1536-height":198,"2048x2048":"https:\/\/elvjournal.elv.com\/wp-content\/uploads\/Liste-Beitrag_python_t10.jpg","2048x2048-width":312,"2048x2048-height":198,"gform-image-choice-sm":"https:\/\/elvjournal.elv.com\/wp-content\/uploads\/Liste-Beitrag_python_t10.jpg","gform-image-choice-sm-width":300,"gform-image-choice-sm-height":190,"gform-image-choice-md":"https:\/\/elvjournal.elv.com\/wp-content\/uploads\/Liste-Beitrag_python_t10.jpg","gform-image-choice-md-width":312,"gform-image-choice-md-height":198,"gform-image-choice-lg":"https:\/\/elvjournal.elv.com\/wp-content\/uploads\/Liste-Beitrag_python_t10.jpg","gform-image-choice-lg-width":312,"gform-image-choice-lg-height":198}},"categories":[{"id":34,"name":"Python &amp; MicroPython","slug":"python-micropython"}],"authors":[{"id":137,"name":"Dr. G\u00fcnter Spanner","slug":"dr-guenter-spanner"}],"document":false,"epaper":"","date":"28. Februar 2026","excerpt":"Interaktiv mit Tkinter: Lerne, wie du in Python grafische Oberfl\u00e4chen erstellst \u2013 von einfachen Labels und Layouts bis zu Projekten wie Spielw\u00fcrfel, Taschenrechner, Analoguhr sowie LED- und Motorsteuerung auf dem Raspberry Pi. Perfekt f\u00fcr deinen Einstieg in GUIs und Automation."},"_links":{"self":[{"href":"https:\/\/de.elv.com\/elvjournal\/wp-json\/wp\/v2\/posts\/1732","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/de.elv.com\/elvjournal\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/de.elv.com\/elvjournal\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/de.elv.com\/elvjournal\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/de.elv.com\/elvjournal\/wp-json\/wp\/v2\/comments?post=1732"}],"version-history":[{"count":10,"href":"https:\/\/de.elv.com\/elvjournal\/wp-json\/wp\/v2\/posts\/1732\/revisions"}],"predecessor-version":[{"id":13302,"href":"https:\/\/de.elv.com\/elvjournal\/wp-json\/wp\/v2\/posts\/1732\/revisions\/13302"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/de.elv.com\/elvjournal\/wp-json\/wp\/v2\/media\/864"}],"wp:attachment":[{"href":"https:\/\/de.elv.com\/elvjournal\/wp-json\/wp\/v2\/media?parent=1732"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/de.elv.com\/elvjournal\/wp-json\/wp\/v2\/categories?post=1732"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/de.elv.com\/elvjournal\/wp-json\/wp\/v2\/tags?post=1732"},{"taxonomy":"post-author","embeddable":true,"href":"https:\/\/de.elv.com\/elvjournal\/wp-json\/wp\/v2\/post-author?post=1732"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}