{"id":7189,"date":"2014-04-10T05:01:09","date_gmt":"2014-04-09T19:01:09","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=7189"},"modified":"2014-04-10T05:01:09","modified_gmt":"2014-04-09T19:01:09","slug":"python-tkinter-install-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/python-tkinter-install-tutorial\/","title":{"rendered":"Python Tkinter Install Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Python\/Tkinter\/Python_Tkinter_Install.jpg\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"Python Tkinter Install Tutorial  (try twirling around bottom of image for a synopsis ... 'do the twirl now')\" src=\"http:\/\/www.rjmprogramming.com.au\/Python\/Tkinter\/Python_Tkinter_Install.png\" title=\"Python Tkinter Install Tutorial\" id='iimgptfb' onmouseover=\"var xqw=this.src; if (xqw.indexOf('gif') != -1) { this.src = 'http:\/\/www.rjmprogramming.com.au\/Python\/Tkinter\/Python_Tkinter_Install.png'; } else if (xqw.indexOf('png') != -1) { this.src = 'http:\/\/www.rjmprogramming.com.au\/Python\/Tkinter\/Python_Tkinter_Install.jpg'; } else { this.src = 'http:\/\/www.rjmprogramming.com.au\/Python\/Tkinter\/Python_Tkinter_Install.gif'; }\"   \/><\/a><p class=\"wp-caption-text\">Python Tkinter Install Tutorial  (try twirling round bottom of image for a synopsis ... 'do the twirl now')<\/p><\/div>\n<p>Have you heard of Python?<\/p>\n<blockquote><p>Python is a programming language that lets you work more quickly and integrate your systems more effectively. You can learn to use Python and see almost immediate gains in productivity and lower maintenance costs.<\/p><\/blockquote>\n<p>Check <span style=\"color:green;\">&#8730;<\/span><\/p>\n<p>How about Tkinter (the Tcl\/TK GUI interface for Python)?<\/p>\n<blockquote><p>Tkinter is a Python binding to the Tk GUI toolkit, as we showed you below with previous relevant <a target=_blank title='Python Tkinter Primer Tutorial' href='#ptpt'>Python Tkinter Primer Tutorial<\/a>. It is the standard Python interface to the Tk GUI toolkit[1] and is Python&#8217;s de facto standard GUI,[2] and is included with the standard Windows and Mac OS X install of Python.<\/p><\/blockquote>\n<p>But what if you have Python installed but no Tkinter (GUI)? &#8230; to test for this &#8230; see &#8230; <a target=_blank title='TkInter - Python Wiki' href='https:\/\/wiki.python.org\/moin\/TkInter#line-68' title='TkInter - Python Wiki'>TkInter &#8211; Python Wiki<\/a>, as is often the case on Apache\/PHP web server setups.<\/p>\n<p>If you get stuck at the <i>import<\/i> line of code with an error message you don&#8217;t have a compiled version of Python where a Tkinter module has been compiled into it.  Before you panic, another check is, do you have two versions of Python co-existing, the more recent of which is not the default &#8230; try the same thing at the command line with <i>python2.7<\/i> or <i>python3.3<\/i>, rather than <i>python<\/i> &#8230; Murphy&#8217;s law being what it is &#8230; a plot by Murphy&#8217;s enemies &#8230; it is unlikely this simple thought resolves your Tkinter usage issue.<\/p>\n<p>You may get errors that talk about the environment variable <i>DISPLAY<\/i> &#8230; well, this means you have no GUI framework on which Tkinter can play?   How could you?   So part of what you will need is Xterm, or the more modern replacement Xquartz, or the more elaborate GNOME Desktop suite of software.<\/p>\n<p>The findings for me were that both were needed &#8230; a sad scenario indeed, if you want to develop some interesting graphical Python software.<\/p>\n<p>From here, the (Linux, in our case) environment becomes important (as you learn the more you get into the OpenSource world) &#8230; and the idea that you should not proceed if you are happy with your current Python, for what you aim to achieve &#8230; but &#8230; when looking for solutions to this problem on the Internet add your environment &#8220;word&#8221; to the search words &#8230; eg. (for me) &#8230; &#8220;Python Tkinter install&#8221; &#8220;CentOS&#8221;<\/p>\n<p>Now will show you some useful links (thanks, OpenSource community) that may help point you in the right direction (environmental issues preclude me from giving more precise exact advice):<\/p>\n<ul>\n<li><a target=_blank title=\"How to install Python 2.7 and Python 3.3 on CentOS 6 | Too Much Data\" href='http:\/\/toomuchdata.com\/2014\/02\/16\/how-to-install-python-on-centos\/'>How to install Python 2.7 and Python 3.3 on CentOS 6 | Too Much Data<\/a> &#8230; ended up installing Python 3.3 as shared library, co-existing with the default Python (which is 2.6) &#8230; so was useful in my case<\/li>\n<li><a target=_blank title=\"python3-tkinter-3.3.0-1.puias6.i686.rpm CentOS 6 Download\" href='http:\/\/pkgs.org\/centos-6\/puias-computational-i386\/python3-tkinter-3.3.0-1.puias6.i686.rpm.html'>python3-tkinter-3.3.0-1.puias6.i686.rpm CentOS 6 Download<\/a> &#8230; taught me that after installing <i>python3.3<\/i> and finding the Tkinter tests failed, that <i>yum install python3-tkinter<\/i> would help, and it did, but the other bits of this webpage&#8217;s advice were not useful for my case<\/li>\n<li><a target=_blank title=\"Tkinter: &quot;Python may not be configured for Tk&quot; - Stack Overflow\" href='http:\/\/stackoverflow.com\/questions\/5459444\/tkinter-python-may-not-be-configured-for-tk'>Tkinter: &quot;Python may not be configured for Tk&quot; &#8211; Stack Overflow<\/a> &#8230; taught me that I would need to do <i>yum install tk-devel<\/i> (which did happen for me, at one stage)<\/li>\n<li><a target=_blank title=\"TkDocs - Tk Tutorial\" href='http:\/\/www.tkdocs.com\/tutorial\/index.html'>TkDocs &#8211; Tk Tutorial<\/a> &#8230; may be useful, and should be useful, but maybe not for up to date scenarios &#8230; not used by me much<\/li>\n<li><a target=_blank title=\"CentOS &bull; View topic - [SOLVED] where is xterm?\" href='https:\/\/www.centos.org\/forums\/viewtopic.php?t=1499'>CentOS &bull; View topic &#8211; [SOLVED] where is xterm?<\/a> &#8230; good for advice regarding Xterm (or Xquartz or GNOME Desktop) if last of your issues is that <i>DISPLAY<\/i> error and you want to install the solution locally (see mention of remote idea in last link below)<\/li>\n<li><a target=_blank title=\"HowTos\/VNC-Server - CentOS Wiki\" href='http:\/\/wiki.centos.org\/HowTos\/VNC-Server'>HowTos\/VNC-Server &#8211; CentOS Wiki<\/a> &#8230; you may need, for a local graphics-installed solution to have users who can use Xterm (or Xquartz or GNOME Desktop) as a default environment, or have it switchable, to read this link&#8217;s advice (this brings into play discussions regarding VNC and PuTTY, but this, perhaps, should be for another day)<\/li>\n<li><a target=_blank title=\"FrontPage - Tkinter Wiki\" href='http:\/\/tkinter.unpythonic.net\/wiki\/FrontPage'>FrontPage &#8211; Tkinter Wiki<\/a> &#8230; is more useful after you get the install correct<\/li>\n<li><a target=_blank title=\"linux - Trying to open a GUI from a remote server using Mac but not succesfully - Unix &#038; Linux Stack Exchange\" href='http:\/\/unix.stackexchange.com\/questions\/81263\/trying-to-open-a-gui-from-a-remote-server-using-mac-but-not-succesfully'>linux &#8211; Trying to open a GUI from a remote server using Mac but not succesfully &#8211; Unix &#038; Linux Stack Exchange<\/a> &#8230; the thoughts here are for another time, involving <i>ssh tunnelling<\/i> and <i>X11 forwarding<\/i> to help create your &#8220;graphics source&#8221; remotely (perhaps) to help you out with a server, maybe, that doesn&#8217;t have Xterm nor Xquartz nor a GNOME Desktop ( in such cases to continue on, to find a use for Tkinter you&#8217;ll need something like &#8220;export DISPLAY=[ip address of client allowing X11 forwarding]:0&#8221; )<\/li>\n<\/ul>\n<p>By the way, the test.py programming Python code used is the same as <a target=_blank href='http:\/\/www.rjmprogramming.com.au\/Python\/Tkinter\/tkinter_filebrowser_test.py_GETME' title='tkinter_filebrowser_test.py'>tkinter_filebrowser_test.py<\/a>, as for the previous tutorial.   Curiously, it may not run for you in Python 3.3(?!)<\/p>\n<p>Will leave with a general Python Tcl\/Tk reference link <a target=_blank title=\"Python Tcl\/Tk reference link\" href='https:\/\/docs.python.org\/2\/library\/tkinter.html'>here<\/a>.<\/p>\n<hr \/>\n<p id=\"ptpt\">Previous relevant <a target=_blank title='Python Tkinter Primer Tutorial' href='http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=4863'>Python Tkinter Primer Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Python\/Tkinter\/Python_Tkinter_FileBrowser.jpg\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"Python Tkinter Primer Tutorial  (try twirling round bottom of image for a synopsis ... 'do the twirl now')\" src=\"http:\/\/www.rjmprogramming.com.au\/Python\/Tkinter\/Python_Tkinter_FileBrowser.jpg\" title=\"Python Tkinter Primer Tutorial\" id='imgptfb' onmouseover=\"var xqw=this.src; if (xqw.indexOf('gif') != -1) { this.src = 'http:\/\/www.rjmprogramming.com.au\/Python\/Tkinter\/Python_Tkinter_FileBrowser.png'; } else if (xqw.indexOf('png') != -1) { this.src = 'http:\/\/www.rjmprogramming.com.au\/Python\/Tkinter\/Python_Tkinter_FileBrowser.jpg'; } else { this.src = 'http:\/\/www.rjmprogramming.com.au\/Python\/Tkinter\/Python_Tkinter_FileBrowser.gif'; }\"   \/><\/a><p class=\"wp-caption-text\">Python Tkinter Primer Tutorial  (try twirling round bottom of image for a synopsis ... 'do the twirl now')<\/p><\/div>\n<p>Have you heard of Python?<\/p>\n<blockquote><p>Python is a programming language that lets you work more quickly and integrate your systems more effectively. You can learn to use Python and see almost immediate gains in productivity and lower maintenance costs.<\/p><\/blockquote>\n<p>Check <span style=\"color:green;\">&#8730;<\/span><\/p>\n<p>How about Tkinter (the Tcl\/TK GUI interface for Python)?<\/p>\n<blockquote><p>Tkinter is a Python binding to the Tk GUI toolkit. It is the standard Python interface to the Tk GUI toolkit[1] and is Python&#8217;s de facto standard GUI,[2] and is included with the standard Windows and Mac OS X install of Python.<\/p><\/blockquote>\n<p>Check <span style=\"color:green;\">&#8730;<\/span> (we hope)<\/p>\n<p>Have used it for <a target=_blank title='Python Tkinter GUI' href='http:\/\/docs.activestate.com\/activepython\/2.6\/python\/library\/tkinter.html'>Games Programming<\/a> and it is great at <a target=_blank title='Python and the SAX API parsing XML' href='http:\/\/mail.python.org\/pipermail\/python-dev\/2000-October\/009946.html'>parsing XML via the SAX API<\/a>.<\/p>\n<p>Python has some really interesting data structures such as tuples, lists, sets, dictionaries for instance &#8230; read more <a target=_blank title='Python data types' href='http:\/\/zetcode.com\/lang\/python\/datatypes\/'>here<\/a>.<\/p>\n<p>In this primer  <a target=_blank title='click picture' href='http:\/\/www.rjmprogramming.com.au\/Python\/Tkinter\/Python_Tkinter_FileBrowser.jpg'>tutorial<\/a> you can see Tkinter being used by Python to display a file browser dialog, from which you can select a jpeg file to display with the default operating system image application (in our case, on a Mac laptop, this is Preview).<\/p>\n<p>Here is another Python tutorial called <a target=_blank title='Python tutorial' href='http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=1687'>Python Processing Directory Filespec Primer Tutorial<\/a>.<\/p>\n<p>Useful tutorials helping with this tutorial were<\/p>\n<ul>\n<li><a target=_blank title='Useful tutorial 1' href='https:\/\/wiki.python.org\/moin\/TkInter'>Useful tutorial 1<\/a><\/li>\n<li><a target=_blank title='Useful tutorial 2' href='http:\/\/stackoverflow.com\/questions\/3124556\/clean-way-to-launch-the-web-browser-from-shell-script\/3124634#3124634'>Useful tutorial 2<\/a><\/li>\n<li><a target=_blank title='Useful tutorial 3' href='http:\/\/stackoverflow.com\/questions\/89228\/calling-an-external-command-in-python'>Useful tutorial 3<\/a><\/li>\n<\/ul>\n<p>Link to Python information &#8230; <a target=_blank href='http:\/\/en.wikipedia.org\/wiki\/Python_%28programming_language%29' title='Python information from Wikipedia'> from Wikipedia<\/a> &#8230; where quote up the top resides.<br \/>\nLink to Tkinter information &#8230; <a target=_blank href='http:\/\/en.wikipedia.org\/wiki\/Tkinter' title='Tkinter information from Wikipedia'> from Wikipedia<\/a> &#8230; where quote up the top resides.<\/p>\n<p>Link to some Python downloadable programming source code which you could rename to <a target=_blank href='http:\/\/www.rjmprogramming.com.au\/Python\/Tkinter\/tkinter_filebrowser_test.py_GETME' title='tkinter_filebrowser_test.py'>tkinter_filebrowser_test.py<\/a><\/p>\n<p>Link to Python website &#8230; <a target=_blank href='http:\/\/www.python.org\/' title='Home of Python'>Home of Python &#8230; where quote up the top resides<\/a><br \/>\nLink to Python jobs done &#8230; <a target=_blank href='http:\/\/www.rjmprogramming.com.au\/Python\/' title='Python example usage'>Python jobs done<\/a> &#8230; personal experience<br \/>\nAnd yes, it&#8217;s true &#8230; the language name is a fond reference to <a target=_blank title='Monty Python' href='http:\/\/www.youtube.com\/watch?v=T70-HTlKRXo'>Monty Python<\/a>\n<\/p>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d4863' onclick='var dv=document.getElementById(\"d4863\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"http:\/\/www.rjmprogramming.com.au\/wordpress\/?s=Python\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d4863' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr \/>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d7189' onclick='var dv=document.getElementById(\"d7189\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"http:\/\/www.rjmprogramming.com.au\/wordpress\/?tag=Python\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d7189' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Have you heard of Python? Python is a programming language that lets you work more quickly and integrate your systems more effectively. You can learn to use Python and see almost immediate gains in productivity and lower maintenance costs. Check &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/python-tkinter-install-tutorial\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,17,25,37],"tags":[195,504,549,707,882,997,1009,1012,1192,1246,1286,1319,1387,1470,1483,1485],"class_list":["post-7189","post","type-post","status-publish","format-standard","hentry","category-elearning","category-gui","category-networking","category-tutorials","tag-centos","tag-gnome-desktop","tag-gui","tag-linux","tag-opensource","tag-programming","tag-putty","tag-python","tag-ssh-tunnel","tag-tcltk","tag-tkinter","tag-tutorial","tag-vnc","tag-x11-forwarding","tag-xquartz","tag-xterm"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/7189"}],"collection":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/comments?post=7189"}],"version-history":[{"count":0,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/7189\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=7189"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=7189"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=7189"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}