{"id":370,"date":"2018-07-03T15:24:10","date_gmt":"2018-07-03T13:24:10","guid":{"rendered":"http:\/\/pythonprogramming.altervista.org\/?p=370"},"modified":"2019-07-12T12:50:22","modified_gmt":"2019-07-12T10:50:22","slug":"tkinter-example-2-a-calculator","status":"publish","type":"post","link":"https:\/\/pythonprogramming.altervista.org\/tkinter-example-2-a-calculator\/","title":{"rendered":"Tkinter &#8211; Example 2: a calculator"},"content":{"rendered":"<h2>A calculator with tkinter<\/h2>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-719\" src=\"https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2018\/07\/claculator.png\" alt=\"\" width=\"537\" height=\"269\" srcset=\"https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2018\/07\/claculator.png 1008w, https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2018\/07\/claculator-320x160.png 320w, https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2018\/07\/claculator-768x385.png 768w, https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2018\/07\/claculator-960x481.png 960w\" sizes=\"auto, (max-width: 537px) 100vw, 537px\" \/><\/p>\n<p>We are going to make another example with tkinter, building an app to create a calculator. Let&#8217;s start analysing each widget in the window.<\/p>\n<h2>The display (Entry widget)<\/h2>\n<p>To make the display we are going to use the following code:<\/p>\n<pre class=\"lang:default decode:true\">   ########################\r\n   ####  the display  #####\r\n   ########################\r\n\r\ndisplay = tk.StringVar()\r\n# relief can be FLAT or RIDGE or RAISED or SUNKEN GROOVE\r\nentry_display = tk.Entry(self)\r\nentry_display['relief'] = tk.FLAT\r\nentry_display['textvariable'] = display\r\nentry_display['justify'] = 'right'\r\nentry_display['bd'] = 30\r\nentry_display['bg'] = 'orange'\r\nentry_display.pack(side=tk.TOP, expand=tk.YES, fill=tk.BOTH)<\/pre>\n<h2>Let&#8217;s comment the code<\/h2>\n<pre class=\"lang:default decode:true \"># THE VARIABLE TO GET THE VALUE IN THE DISPLAY\r\ndisplay = tk.StringVar()\r\n\r\n# THE ENTRY OBJECT = DISPLAY\r\nentry_display = tk.Entry(self)\r\n\r\n# THE BORDER = FLAT\r\nentry_display['relief'] = tk.FLAT\r\n\r\n# IT CAN BE FLAT or RIDGE or RAISED or SUNKEN GROOVE\r\n\r\n# THE VARIABLE SEEN BEFOR\r\nentry_display['textvariable'] = display\r\n# JUSTIFICATED TO THE RIGHT\r\nentry_display['justify'] = 'right'\r\n# THE THIKNESS\r\nentry_display['bd'] = 30\r\n# THE BACKGROUND COLOR\r\nentry_display['bg'] = 'orange'\r\n# TO SEE IT, AT THE TOP, EXTENDED AS LONG AS THE WINDOW\r\nentry_display.pack(side=tk.TOP, expand=tk.YES, fill=tk.BOTH)<\/pre>\n<p>&nbsp;<\/p>\n<h2>The whole code<\/h2>\n<pre class=\"lang:default decode:true \">from tkinter import *\r\n\r\n#This function returns a Frame\r\ndef iCalc(source, side):\r\n    \"Returns a Frame object yet packed and expanded, to shorten the code\"\r\n    # the bd is the border of the frame\r\n    storeObj = Frame(source, borderwidth=10, bd=1, bg=\"gray\")\r\n    # the pack methos is needed to diplay the object\r\n    storeObj.pack(side=side, expand=YES, fill=BOTH)\r\n    return storeObj\r\n\r\n\r\ndef button(source, side, text, command=None):\r\n    \"Return a Button object that is packed yet\"\r\n    storeObj = Button(source, text=text, command=command)\r\n    storeObj.pack(side=side, expand=YES, fill=BOTH)\r\n    return storeObj\r\n\r\n# This class inherit from Frame\r\nclass App(Frame):\r\n    def __init__(self):\r\n        Frame.__init__(self)\r\n        self.option_add(\"*Font\", \"arial 20 bold\")\r\n        self.pack(expand=YES, fill=BOTH)\r\n        self.master.title(\"Calculator\")\r\n\r\n\r\n        #  THE DISPLAY\r\n        display = StringVar()\r\n        # relief can be FLAT or RIDGE or RAISED or SUNKEN GROOVE\r\n        entry = Entry(self, relief=FLAT, textvariable=display, justify='right', bd=15, bg='orange')\r\n        entry.pack(side=TOP)\r\n        # I added an action to calculate the operation when Return (Enter) is hit\r\n        entry.focus()\r\n        # You can hit enter to get the result instead of clicking =\r\n        self.master.bind(\"&lt;Return&gt;\", lambda e, s=self, storeObj=display: s.calc(storeObj))\r\n        # YOu can click del button on the keyboard to cancel\r\n        self.master.bind(\"&lt;Delete&gt;\", lambda e, s=self, storeObj=display: storeObj.set(\"\"))\r\n        self.master.bind(\"&lt;BackSpace&gt;\", lambda e, s=self, storeObj=display: storeObj.set(\"\"))\r\n\r\n        # Thi is the frame for the [C] button\r\n        erase = iCalc(self, TOP)\r\n        clearBut = \"C\"\r\n        button(erase, LEFT, clearBut, lambda storeObj=display, q=clearBut: storeObj.set(\"\"))\r\n\r\n        for numBut in (\"789\/\", \"456*\", \"123-\", \"0.+\"):\r\n            functionNum = iCalc(self, TOP)\r\n            for char in numBut:\r\n                button(functionNum, LEFT, char, lambda storeObj=display, q=char: storeObj.set(storeObj.get() + q))\r\n        equalButton = iCalc(self, TOP)\r\n\r\n        for iEqual in \"=\":\r\n            if iEqual == \"=\":\r\n                btniEqual = button(equalButton, LEFT, iEqual)\r\n                btniEqual.bind(\"&lt;ButtonRelease-1&gt;\", lambda e, s=self, storeObj=display: s.calc(storeObj), '+')\r\n            else:\r\n                btniEqual = button(equalButton, LEFT, iEqual, lambda storeObj=display, s='%s' % iEqual: storeObj.set(storeObj.get() + s))\r\n\r\n    def calc(self, display):\r\n        try:\r\n        \t# Sets the display to the evaluation of the string in the display itself, i.e. calculate the result\r\n            display.set(eval(display.get()))\r\n        except:\r\n        \t# if something goes wrong with the result\r\n            display.set(\"ERROR\")\r\n\r\n\r\nif __name__ == '__main__':\r\n    App().mainloop()\r\n<\/pre>\n<p>&nbsp;<\/p>\n<h2>Video to show the app running<\/h2>\n<div style=\"width: 747px;\" class=\"wp-video\"><video class=\"wp-video-shortcode\" id=\"video-370-1\" width=\"747\" height=\"467\" preload=\"metadata\" controls=\"controls\"><source type=\"video\/mp4\" src=\"https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2018\/07\/Calculator.mp4?_=1\" \/><a href=\"https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2018\/07\/Calculator.mp4\">https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2018\/07\/Calculator.mp4<\/a><\/video><\/div>\n<h2>Version 2<\/h2>\n<p><a href=\"https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2018\/07\/v2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1525\" src=\"https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2018\/07\/v2.png\" alt=\"\" width=\"339\" height=\"385\" srcset=\"https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2018\/07\/v2.png 339w, https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2018\/07\/v2-320x363.png 320w\" sizes=\"auto, (max-width: 339px) 100vw, 339px\" \/><\/a><\/p>\n<p>In this version we have a different look, with a very big delete button.<\/p>\n<pre class=\"lang:default decode:true \">from tkinter import *\r\n\r\n#This function returns a Frame\r\ndef iCalc(source, side):\r\n    \"Returns a Frame object yet packed and expanded, to shorten the code\"\r\n    # the bd is the border of the frame\r\n    storeObj = Frame(source, borderwidth=10, bd=1, bg=\"gray\")\r\n    # the pack methos is needed to diplay the object\r\n    storeObj.pack(side=side, expand=YES, fill=BOTH)\r\n    return storeObj\r\n\r\n\r\ndef button(source, side, text, command=None):\r\n    \"Return a Button object that is packed yet\"\r\n    storeObj = Button(source, text=text, command=command)\r\n    storeObj.pack(side=side, expand=YES, fill=BOTH)\r\n    return storeObj\r\n\r\n# This class inherit from Frame\r\nclass App(Frame):\r\n    def __init__(self):\r\n        Frame.__init__(self)\r\n        self.option_add(\"*Font\", \"arial 20 bold\")\r\n        self.pack(expand=YES, fill=BOTH)\r\n        self.master.title(\"Calculator\")\r\n\r\n\r\n        #  THE DISPLAY\r\n        display = StringVar()\r\n        # relief can be FLAT or RIDGE or RAISED or SUNKEN GROOVE\r\n        entry = Entry(self, relief=FLAT, textvariable=display, justify='right', bd=15, bg='orange')\r\n        entry.pack(side=TOP)\r\n        # I added an action to calculate the operation when Return (Enter) is hit\r\n        entry.focus()\r\n        # You can hit enter to get the result instead of clicking =\r\n        self.master.bind(\"&lt;Return&gt;\", lambda e, s=self, storeObj=display: s.calc(storeObj))\r\n        # YOu can click del button on the keyboard to cancel\r\n        self.master.bind(\"&lt;Delete&gt;\", lambda e, s=self, storeObj=display: storeObj.set(\"\"))\r\n        self.master.bind(\"&lt;BackSpace&gt;\", lambda e, s=self, storeObj=display: storeObj.set(\"\"))\r\n\r\n        # Thi is the frame for the [C] button\r\n        erase = iCalc(self, LEFT)\r\n        clearBut = \"Delete\"\r\n        button(erase, LEFT, clearBut, lambda storeObj=display, q=clearBut: storeObj.set(\"\"))\r\n\r\n        for numBut in (\"789\/\", \"456*\", \"123-\", \"0.+\"):\r\n            functionNum = iCalc(self, TOP)\r\n            for char in numBut:\r\n                button(functionNum, LEFT, char, lambda storeObj=display, q=char: storeObj.set(storeObj.get() + q))\r\n        equalButton = iCalc(self, TOP)\r\n\r\n        for iEqual in \"=\":\r\n            if iEqual == \"=\":\r\n                btniEqual = button(equalButton, LEFT, iEqual)\r\n                btniEqual.bind(\"&lt;ButtonRelease-1&gt;\", lambda e, s=self, storeObj=display: s.calc(storeObj), '+')\r\n            else:\r\n                btniEqual = button(equalButton, LEFT, iEqual, lambda storeObj=display, s='%s' % iEqual: storeObj.set(storeObj.get() + s))\r\n\r\n    def calc(self, display):\r\n        try:\r\n        \t# Sets the display to the evaluation of the string in the display itself, i.e. calculate the result\r\n            display.set(eval(display.get()))\r\n        except:\r\n        \t# if something goes wrong with the result\r\n            display.set(\"ERROR\")\r\n\r\n\r\nif __name__ == '__main__':\r\n    App().mainloop()\r\n<\/pre>\n<h2>Minimal layout: Mini-Calculator<\/h2>\n<p>The <a href=\"https:\/\/pythonprogramming.altervista.org\/a-simple-calculator-with-tkinter\/\">article with the mini-calculator code<\/a> (another version, minimal).<\/p>\n\t<!----- pubblicit\u00e0-------- vedi h:\\ads\\codice_di_prima.txt per il codice che era qui --------------------->\r\n<script async src=\"https:\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script>\r\n<!-- Altervista-pythonprogramming-336X280 -->\r\n<ins class=\"adsbygoogle\"\r\n     style=\"display:block\"\r\n     data-ad-client=\"ca-pub-4189782812829764\"\r\n     data-ad-slot=\"2548661001\"\r\n     data-ad-format=\"auto\"><\/ins>\r\n<script>\r\n     (adsbygoogle = window.adsbygoogle || []).push({});\r\n<\/script>\r\n<h4>Tkinter test for students<\/h4>\r\n\r\n\r\n<script>\r\nvar title = \"Tkinter posts\";\r\n\t\tvar links = [\r\n[\"https:\/\/pythonprogramming.altervista.org\/tkinter-app-to-make-a-different-test-for-every-student-part-1\/\",\"Tk Test Marker I\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/tkinter-testmaker-part-ii\/\",\"Tk Test Maker II\"],\t\r\n[\"https:\/\/pythonprogramming.altervista.org\/tkinter-tests-app-part-3\/\",\"Tk test Maker III\"]\r\n];\r\n\t\t\r\n\t<\/script>\r\n<script>\r\n\t\r\nif (typeof next2 != \"undefined\"){let next2 = 0;}\r\n\t\r\nnext2 = 0;\r\n\thtml = \"\";\/\/<b style='color:coral;font-size:1.2em'>Other posts about \" + title + \"<\/b><br>\";\r\nfor (address of links) \r\n{\r\n\r\n\tif (next2 == 1){\r\n\t\thtml += \"<div style='background:coral'>\";\r\n\t\thtml += \"Next link => <a href='\" + address[0] + \"'>\" + address[1] + \"<\/a>\";\r\n\t\thtml += \"<\/div><br>\";\r\n\t\tnext2 = 0;\r\n\t}\r\n\tif (address[0] == document.URL) {\r\n\t\tnext2 = 1;\r\n\t}\r\n}\r\n\r\nif (typeof next != \"undefined\") {let next = 0;}\r\nif (typeof addressStart != \"undefined\") {let addressStart = \"\";}\r\nnext = 0;\r\naddressStart = \"<a href='\";\r\nfor (address of links) {\r\n\tif (next == 1){\r\n\t\thtml += \">>>\" + addressStart + address[0] + \"'>\" + address[1] + \"<\/a><br>\";\r\n\t\tnext = 0;\r\n\t}\r\n\telse if (addressStart + address[0] != document.URL)\r\n\t{\r\n\t\thtml += addressStart + address[0] + \"'>\" + address[1] + \"<\/a><br>\";\r\n\t}\r\n\telse\r\n\t{\r\n\t\tnext = 1;\r\n\t\tnext_address = address[0]\r\n\t\tnext_title = address[1]\r\n\t\thtml += \"<span style='color:gray'>\" + address[1] + \"<\/span><br>\";\r\n\t}\r\n\r\n}\r\n\r\n\thtml += `<span style=\"font-size:8px\">Powered by <a href=\"https:\/\/pythonprogramming.altervista.org\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2673\" src=\"https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2019\/06\/altervista2.png\" alt=\"\" width=\"70\" height=\"25\" srcset=\"https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2019\/06\/altervista2.png 156w, https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2019\/06\/altervista2-150x56.png 150w\" sizes=\"auto, (max-width: 70px) 100vw, 70px\" \/>pythonprogramming.altervista.org<\/a><\/span>`\r\n\thtml = \"<div style='background:yellow'>\" + html + \"<\/div>\";\r\n\tdocument.write(html)\r\n<\/script>\r\n\t\r\n\r\n<h4>Tkinter articles<\/h4>\r\n<!-- calculator with memo -->\r\n<a href=\"https:\/\/pythonprogramming.altervista.org\/free-calculator-memo-with-tkinter-support-markdown-to-html-saving-too\/\">\r\n<img decoding=\"async\" src=\"https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2020\/03\/calcmemopy_banner.png\" width=\"100%\"><\/a>\r\n<script>\r\nvar title = \"Tkinter posts\";\r\n\t\tvar links = [\r\n\t\t\t[\"https:\/\/pythonprogramming.altervista.org\/?p=5719&preview=true\",\"Presentation app with SVG files\"],\r\n\t\t\t[\"https:\/\/pythonprogramming.altervista.org\/png-joined-in-one-pdf-files\/\",\"Join png into pdf\"],\r\n\t\t\t[\"https:\/\/pythonprogramming.altervista.org\/free-app-imgslide-3-1-slide-images-and-join-them-into-a-pdf\/\",\"ImageSlider 3.1\"],\r\n\t\t\t[\"https:\/\/pythonprogramming.altervista.org\/tkinter-to-show-svg-files-svgslider-1-0\/\",\"SVGSlider 1.0\"],\r\n\t\t\t[\"https:\/\/pythonprogramming.altervista.org\/imageslider-3-0-tkinter-app-to-show-images-like-in-a-presentation\/\",\"ImageSlider 3.0\"],\r\n\t\t\t[\"https:\/\/pythonprogramming.altervista.org\/tkinter-shows-an-svg-file\/\",\"SVG in tkinter\"],\r\n\t\t\t[\"https:\/\/pythonprogramming.altervista.org\/tkinter-tests-maker-app-part-iv-add-a-menu-with-tkinter\/\",\"Add a menu with tkinter\"],\r\n\t\t\t[\"https:\/\/pythonprogramming.altervista.org\/free-pdf-maker-app-with-python\/\",\"tkinter make pdf\"],\r\n\t\t\t[\"https:\/\/pythonprogramming.altervista.org\/calcpy-2-0-the-second-and-final-part-of-calculator\/\",\"Live coding Calculator app part 2\"],\r\n\t\t\t[\"https:\/\/pythonprogramming.altervista.org\/split-every-page-in-a-pdf-i-a-different-pdf\/\",\"Split a pdf in different files\"],\r\n\t\t\t[\"https:\/\/pythonprogramming.altervista.org\/python-calculator-from-skratch-part-1-calcpy\/\",\"Calculator from skratch p.1\"], \r\n\t\t\t[\"https:\/\/pythonprogramming.altervista.org\/python-and-tkinter-fully-working-listbox-to-do-app-for-skratch\/\",\"Tkinter ToDo App\"],\r\n\t\t\t[\"https:\/\/pythonprogramming.altervista.org\/copy-and-paste-tkinter-widget-code-app\/\",\"Copy and paste app for tkinter widgets\"],\r\n\t\t\t[\"https:\/\/pythonprogramming.altervista.org\/calcdoc-py-a-tkinter-app-to-memorize-operations\/\",\"calcdoc.py: a great calculator memo app\"],\r\n\t\t\t[\"https:\/\/pythonprogramming.altervista.org\/tkinter-calculator-with-memo-of-operations\/\",\"Calculator + list of operations\"],\r\n\t\t\t[\"https:\/\/pythonprogramming.altervista.org\/tkinter-smallest-calculator-ever\/\", \"Smallest calculator\"],\r\n\t\t\t[\"https:\/\/pythonprogramming.altervista.org\/python-gui-with-tkinter-labels-with-text-and-images\/\",\"Labels with images and text\"],\r\n\t[\"https:\/\/pythonprogramming.altervista.org\/a-toolbar-for-python-with-tkinter\/\",\"Toolbar in tkinter\"],\r\n\t[\"https:\/\/pythonprogramming.altervista.org\/tkinter-grid-system-how-to-expand-a-button\/\",\"Fit Buttons to the Window\"],\r\n\t\t[\"https:\/\/pythonprogramming.altervista.org\/tkinter-application-launcher-python-gui\/\",\"Tkinter app Laucher\"],\r\n\t\t[\"https:\/\/pythonprogramming.altervista.org\/tkinter-and-how-to-add-an-image-to-a-button\/\", \"Image on a tkinter Button\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/tkinter-imagebrowser-2-with-canvas\/\", \"Tkinter image browser 2 (canvas)\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/tkinter-image-broswer\/\",\"Tkinter image browser (label)\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/tkinter-to-make-pdf-fast-and-free-with-text-or-html\/\",\"Create PDF with Tkinter Text widget\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/tkinter-app-to-evaluate-tests-part-1\/\",\"Tkinter App to Evaluate tests\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/simple-presentation-in-pure-python-while-you-learn-tkinter\/\",\"Presentation with Python\/tkinter\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/tkinter-entry-widgets-example-make-a-shuffler-app\/\",\"Tkinter example: entry to shuffle lists\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/move-a-rectangle-with-text-inside-of-it-with-tkinter\/\",\"Moving a text with tkinter\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/tkinter-and-ttk-the-option-menu-widget\/\",\"Tkinter's OptionMenu (and ttk)\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/tkinter-app-to-watch-videos-with-live-coding\/\",\t\t\t\t\t\"Tkinter to watch videos\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/type-reader-app-in-python-pc-read-the-letters-you-type-tkinter\/\",\t\"Type Reader App\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/create-a-new-tkinter-widget-inputbox\/\",\t\t\t\t\t\t\t\"Create your Inputbox\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/tkinter-open-a-new-window-and-just-one\/\", \t\t\t\t\t\t\"Open only one more window\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/a-simple-test-maker-with-python-and-tkinter\/\", \t\t\t\t\t\"Test maker with tkinter\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/my-personal-notepad-toggle-tkinter-fullscreen\/\",\t\t\t\t\t\"Ebook maker with tkinter\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/tkinter-and-listbox-1\/\", \t\t\t\t\t\t\t\t\t\t\t\"Tkinter & listbox 2019 - 1\"],\r\n['https:\/\/pythonprogramming.altervista.org\/tkinter-using-a-gui-graphic-user-interface-with-python-part-1\/', \t'Create a window'],\r\n['https:\/\/pythonprogramming.altervista.org\/tkinter-to-make-a-window-video-1\/', \t\t\t\t\t\t\t\t'Create a window part 2'],\r\n[\"https:\/\/pythonprogramming.altervista.org\/create-more-windows-with-tkinter\/\",\t\t\t\t\t\t\t\t\"More windows tkinter!\"],\r\n['https:\/\/pythonprogramming.altervista.org\/tkinter-part-2-binding\/', \t\t\t\t\t\t\t\t\t\t'Binding functions to key\/button '],\r\n\t\t\t[\"https:\/\/pythonprogramming.altervista.org\/all-tkinter-posts\/\",\">>>ALL TKINTER POSTS>>>\"]\r\n\t\t];\r\n\t\t\r\n\t<\/script>\r\n<script>\r\n\t\r\nif (typeof next2 != \"undefined\"){let next2 = 0;}\r\n\t\r\nnext2 = 0;\r\n\thtml = \"\";\/\/<b style='color:coral;font-size:1.2em'>Other posts about \" + title + \"<\/b><br>\";\r\nfor (address of links) \r\n{\r\n\r\n\tif (next2 == 1){\r\n\t\thtml += \"<div style='background:coral'>\";\r\n\t\thtml += \"Next link => <a href='\" + address[0] + \"'>\" + address[1] + \"<\/a>\";\r\n\t\thtml += \"<\/div><br>\";\r\n\t\tnext2 = 0;\r\n\t}\r\n\tif (address[0] == document.URL) {\r\n\t\tnext2 = 1;\r\n\t}\r\n}\r\n\r\nif (typeof next != \"undefined\") {let next = 0;}\r\nif (typeof addressStart != \"undefined\") {let addressStart = \"\";}\r\nnext = 0;\r\naddressStart = \"<a href='\";\r\nfor (address of links) {\r\n\tif (next == 1){\r\n\t\thtml += \">>>\" + addressStart + address[0] + \"'>\" + address[1] + \"<\/a><br>\";\r\n\t\tnext = 0;\r\n\t}\r\n\telse if (addressStart + address[0] != document.URL)\r\n\t{\r\n\t\thtml += addressStart + address[0] + \"'>\" + address[1] + \"<\/a><br>\";\r\n\t}\r\n\telse\r\n\t{\r\n\t\tnext = 1;\r\n\t\tnext_address = address[0]\r\n\t\tnext_title = address[1]\r\n\t\thtml += \"<span style='color:gray'>\" + address[1] + \"<\/span><br>\";\r\n\t}\r\n\r\n}\r\n\r\n\thtml += `<span style=\"font-size:8px\">Powered by <a href=\"https:\/\/pythonprogramming.altervista.org\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2673\" src=\"https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2019\/06\/altervista2.png\" alt=\"\" width=\"70\" height=\"25\" srcset=\"https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2019\/06\/altervista2.png 156w, https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2019\/06\/altervista2-150x56.png 150w\" sizes=\"auto, (max-width: 70px) 100vw, 70px\" \/>pythonprogramming.altervista.org<\/a><\/span>`\r\n\thtml = \"<div style='background:yellow'>\" + html + \"<\/div>\";\r\n\tdocument.write(html)\r\n<\/script>\n","protected":false},"excerpt":{"rendered":"Create a calculator with Python and the tkinter gui module.\n<a class=\"moretag\" href=\"https:\/\/pythonprogramming.altervista.org\/tkinter-example-2-a-calculator\/\"> [...]<\/a>","protected":false},"author":1,"featured_media":719,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","footnotes":""},"categories":[1,122,49],"tags":[128,106,129,4,51],"class_list":["post-370","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-examples","category-gui","category-tkinter","tag-calculator","tag-code","tag-example","tag-python","tag-tkinter"],"avopt_banners_inside_post":true,"avopt_banners_on_page":true,"av_copy_from":"","av_sharing_message":"","av_sharing_allowed":false,"av_sharing_on":{"fb":[],"tw":[]},"av_allow_affiliate_banner":false,"av_allow_affiliate_multi_banner":false,"av_show_affiliation_buy_button":false,"av_post_rating":true,"av_have_post_rating_value":false,"av_is_artificial_intelligence_content":false,"_links":{"self":[{"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/posts\/370","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/comments?post=370"}],"version-history":[{"count":21,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/posts\/370\/revisions"}],"predecessor-version":[{"id":1543,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/posts\/370\/revisions\/1543"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/media\/719"}],"wp:attachment":[{"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/media?parent=370"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/categories?post=370"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/tags?post=370"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}