Most viewed recipes tagged "tkinter"http://code.activestate.com/recipes/tags/tkinter/views/2017-06-19T18:22:01-07:00ActiveState Code RecipesTkinter table with scrollbars (Python)
2017-05-06T19:06:05-07:00Miguel Martínez Lópezhttp://code.activestate.com/recipes/users/4189907/http://code.activestate.com/recipes/580793-tkinter-table-with-scrollbars/
<p style="color: grey">
Python
recipe 580793
by <a href="/recipes/users/4189907/">Miguel Martínez López</a>
(<a href="/recipes/tags/scrollbars/">scrollbars</a>, <a href="/recipes/tags/table/">table</a>, <a href="/recipes/tags/tkinter/">tkinter</a>).
Revision 13.
</p>
<p>I created here a tkinter table with scrollbar support. I use one of my other recipes for the mousewheel support and scrolling:</p>
<p><a href="https://code.activestate.com/recipes/580640-scrolling-frame-with-mouse-wheel-support" rel="nofollow">https://code.activestate.com/recipes/580640-scrolling-frame-with-mouse-wheel-support</a></p>
Frame with border color for Tkinter (Python)
2017-04-17T11:25:02-07:00Miguel Martínez Lópezhttp://code.activestate.com/recipes/users/4189907/http://code.activestate.com/recipes/580735-frame-with-border-color-for-tkinter/
<p style="color: grey">
Python
recipe 580735
by <a href="/recipes/users/4189907/">Miguel Martínez López</a>
(<a href="/recipes/tags/border/">border</a>, <a href="/recipes/tags/color/">color</a>, <a href="/recipes/tags/frame/">frame</a>, <a href="/recipes/tags/tkinter/">tkinter</a>).
</p>
<p>This trick show how to add a border color to frame. These are the important configurations:</p>
<pre class="prettyprint"><code> highlightbackground="your border color here"
highlightcolor="your border color here"
highlightthickness="the border width"
bd= 0
</code></pre>
Tkinter table (Python)
2017-05-02T21:19:51-07:00Miguel Martínez Lópezhttp://code.activestate.com/recipes/users/4189907/http://code.activestate.com/recipes/580786-tkinter-table/
<p style="color: grey">
Python
recipe 580786
by <a href="/recipes/users/4189907/">Miguel Martínez López</a>
(<a href="/recipes/tags/table/">table</a>, <a href="/recipes/tags/tkinter/">tkinter</a>).
Revision 24.
</p>
<p>Table of data for tkinter.</p>
<p>Here there is an improved vesion with vertical scrollbar support:</p>
<p><a href="https://code.activestate.com/recipes/580793-tkinter-table-with-scrollbars" rel="nofollow">https://code.activestate.com/recipes/580793-tkinter-table-with-scrollbars</a></p>
Simple audio with ctypes and SDL also for Tkinter (Python)
2015-08-17T18:54:17-07:00Jiri Justrahttp://code.activestate.com/recipes/users/4192188/http://code.activestate.com/recipes/579070-simple-audio-with-ctypes-and-sdl-also-for-tkinter/
<p style="color: grey">
Python
recipe 579070
by <a href="/recipes/users/4192188/">Jiri Justra</a>
(<a href="/recipes/tags/audio/">audio</a>, <a href="/recipes/tags/sdl/">sdl</a>, <a href="/recipes/tags/sdl_mixer/">sdl_mixer</a>, <a href="/recipes/tags/tkinter/">tkinter</a>).
Revision 3.
</p>
<p>I've needed just to play audio in my Tkinter application, but it seems there is no easy way to do this, so I have made this simple code. It is small ctypes wrapper around SDL_mixer.</p>
<p>It should work for Win and *nix also .. I've tested it on ubuntu-14.04.3-desktop-i386</p>
Simple multicolumn listbox for tkinter (Python)
2017-05-02T22:27:15-07:00Miguel Martínez Lópezhttp://code.activestate.com/recipes/users/4189907/http://code.activestate.com/recipes/580794-simple-multicolumn-listbox-for-tkinter/
<p style="color: grey">
Python
recipe 580794
by <a href="/recipes/users/4189907/">Miguel Martínez López</a>
(<a href="/recipes/tags/listbox/">listbox</a>, <a href="/recipes/tags/multicolumn/">multicolumn</a>, <a href="/recipes/tags/table/">table</a>, <a href="/recipes/tags/tkinter/">tkinter</a>).
</p>
<p>This recipe makes easy to work a treeview widget like a table.</p>
<p>It has several options for styling:</p>
<ul>
<li>heading_anchor</li>
<li>heading_font</li>
<li>heading_background</li>
<li>heading_foreground</li>
<li>cell_anchor</li>
<li>cell_background</li>
<li>cell_foreground</li>
<li>cell_font</li>
<li>cell_pady</li>
<li>height</li>
<li>padding</li>
<li>adjust_heading_to_content</li>
<li>stripped_rows</li>
<li>headers</li>
<li>selection_background</li>
<li>selection_foreground</li>
<li>field_background</li>
</ul>
<p>The "command" parameter is a callback and its called each time a row is selected.</p>
Tkinter frame with different border sizes (Python)
2017-05-06T18:45:00-07:00Miguel Martínez Lópezhttp://code.activestate.com/recipes/users/4189907/http://code.activestate.com/recipes/580798-tkinter-frame-with-different-border-sizes/
<p style="color: grey">
Python
recipe 580798
by <a href="/recipes/users/4189907/">Miguel Martínez López</a>
(<a href="/recipes/tags/border/">border</a>, <a href="/recipes/tags/size/">size</a>, <a href="/recipes/tags/tkinter/">tkinter</a>).
</p>
<p>This trick shows how to create a bordered frame with different border size in each side.</p>
Text widget width and height in pixels (Tkinter) (Python)
2016-12-11T13:39:08-08:00Miguel Martínez Lópezhttp://code.activestate.com/recipes/users/4189907/http://code.activestate.com/recipes/578887-text-widget-width-and-height-in-pixels-tkinter/
<p style="color: grey">
Python
recipe 578887
by <a href="/recipes/users/4189907/">Miguel Martínez López</a>
(<a href="/recipes/tags/text/">text</a>, <a href="/recipes/tags/tkinter/">tkinter</a>).
Revision 8.
</p>
<p>The solution consists in putting the Text widget inside a frame, forcing the frame to a fixed size by deactivating size propagation and configuring the Text widget to expand and fill both directions (to stick to the frame borders).</p>
<p><a href="https://stackoverflow.com/questions/14887610/how-to-specify-the-dimensions-of-a-tkinter-text-box-in-pixels" rel="nofollow">https://stackoverflow.com/questions/14887610/how-to-specify-the-dimensions-of-a-tkinter-text-box-in-pixels</a></p>
Scrolled Frame V2 (Python)
2017-05-06T18:54:47-07:00Miguel Martínez Lópezhttp://code.activestate.com/recipes/users/4189907/http://code.activestate.com/recipes/580797-scrolled-frame-v2/
<p style="color: grey">
Python
recipe 580797
by <a href="/recipes/users/4189907/">Miguel Martínez López</a>
(<a href="/recipes/tags/frame/">frame</a>, <a href="/recipes/tags/scrolling/">scrolling</a>, <a href="/recipes/tags/tkinter/">tkinter</a>).
Revision 4.
</p>
<p>This is another version of scrolled frame. It doesn't use Canvas. Instead it does the trick using place geometry manager.</p>
<p>Based on these codes:</p>
<ul>
<li><p>https://github.com/alejandroautalan/pygubu/blob/master/pygubu/widgets/tkscrolledframe.py</p></li>
<li><p>http://wiki.tcl.tk/9223 </p></li>
</ul>
<p>This is my other version of scrolled frame:</p>
<p><a href="https://code.activestate.com/recipes/580640-scrolling-frame-with-mouse-wheel-support/" rel="nofollow">https://code.activestate.com/recipes/580640-scrolling-frame-with-mouse-wheel-support/</a></p>
bind all tkinter "bug" (Python)
2017-05-05T20:33:31-07:00Miguel Martínez Lópezhttp://code.activestate.com/recipes/users/4189907/http://code.activestate.com/recipes/580795-bind-all-tkinter-bug/
<p style="color: grey">
Python
recipe 580795
by <a href="/recipes/users/4189907/">Miguel Martínez López</a>
(<a href="/recipes/tags/all/">all</a>, <a href="/recipes/tags/bind/">bind</a>, <a href="/recipes/tags/binding/">binding</a>, <a href="/recipes/tags/tkinter/">tkinter</a>).
Revision 3.
</p>
<p>This recipes tries to solve the problem of bind_all and unbind_all for tkinter.</p>
<p>When a callback is registered using bind_all method and later it's unregistered using unbind_all, all the callbacks are deleted for the "all" tag event. This makes difficult to register and unregister only one callback at a time. This recipes tries to solve this problem.</p>
<p>Observe the difference between the code below and the recipe. With the code below, when the user clicks nothing happens. But with my recipe it's possible to bind and unbind specific callbacks.</p>
<pre class="prettyprint"><code>try:
from Tkinter import Tk, Frame
except ImportError:
from tkinter import Tk, Frame
root = Tk()
f = Frame(root, width= 300, height=300)
f.pack()
def callback1(event):
print("callback1")
def callback2(event):
print("callback2")
def callback3(event):
print("callback3")
root.bind_all("<1>", callback1, add="+")
f.bind_all("<1>", callback2, add="+")
f.bind_all("<1>", callback3, add="+")
f.unbind_all("<1>")
root.mainloop()
</code></pre>
Python Tkinter Tabs (Python)
2010-06-15T01:50:58-07:00Sunjay Varmahttp://code.activestate.com/recipes/users/4174115/http://code.activestate.com/recipes/577261-python-tkinter-tabs/
<p style="color: grey">
Python
recipe 577261
by <a href="/recipes/users/4174115/">Sunjay Varma</a>
(<a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/sunjay/">sunjay</a>, <a href="/recipes/tags/tabs/">tabs</a>, <a href="/recipes/tags/tkinter/">tkinter</a>, <a href="/recipes/tags/varma/">varma</a>).
Revision 4.
</p>
<p>This tabbed interface is very useful for Tkinter users. I am sure there is a better way to do it, but I did the best I could.</p>
<p>Please enjoy this tabbed interface by SunjayVarma - <a href="http://www.sunjay-varma.com" rel="nofollow">www.sunjay-varma.com</a></p>
<p>UPDATES:
Fixed the index issues. Made it easier to use.</p>
Game of Life - Python 3.4 & tkinter (Python)
2014-09-05T15:02:11-07:00Peter Mhttp://code.activestate.com/recipes/users/4190729/http://code.activestate.com/recipes/578928-game-of-life-python-34-tkinter/
<p style="color: grey">
Python
recipe 578928
by <a href="/recipes/users/4190729/">Peter M</a>
(<a href="/recipes/tags/python3/">python3</a>, <a href="/recipes/tags/tkinter/">tkinter</a>).
</p>
<p>I took this well-know game to design my own solution, and make a GUI for it.</p>
<p>To run the program, you will need to create a txt file with rows of dots, so like this:</p>
<p>......
......
......
......</p>
<p>and name it empty_board.gol
(I have tested this program withwith 55x55)</p>
<p>It is functional and not object oriented.</p>
<p>My game of life algorithm is probably not the best one around (suggestions welcome), but I think this program is a nice demo of with tkinter can do and how easy it is to program GUI's with tkinter.</p>
<p>It has been written and tested in python 3.4 but I guess any version 3 should work, and probably only minor changes are needed to make it work in 2.6 or 2.7 (e.g. change tkinter to Tkinter).</p>
Tkinter treeview like a table or multicolumn listbox (Python)
2017-05-02T22:27:48-07:00Miguel Martínez Lópezhttp://code.activestate.com/recipes/users/4189907/http://code.activestate.com/recipes/580746-tkinter-treeview-like-a-table-or-multicolumn-listb/
<p style="color: grey">
Python
recipe 580746
by <a href="/recipes/users/4189907/">Miguel Martínez López</a>
(<a href="/recipes/tags/editable/">editable</a>, <a href="/recipes/tags/listbox/">listbox</a>, <a href="/recipes/tags/megawidget/">megawidget</a>, <a href="/recipes/tags/multicolumn/">multicolumn</a>, <a href="/recipes/tags/table/">table</a>, <a href="/recipes/tags/tkinter/">tkinter</a>, <a href="/recipes/tags/treeview/">treeview</a>).
Revision 33.
</p>
<p>This trick provides use my other recipe:</p>
<p><a href="https://code.activestate.com/recipes/580794-simple-multicolumn-listbox-for-tkinter/" rel="nofollow">https://code.activestate.com/recipes/580794-simple-multicolumn-listbox-for-tkinter/</a></p>
<p>This recipes defines a <em>Tk_Table:</em> A table that extends the multicolumn listbox adding row numbers, making the cells editable and adding autoscrollbars.</p>
<p><em>Tk_Table</em></p>
<p>It has the same options than <em>Multicolumn_Listbox</em>, and some extra parameters to configure the new functionality.</p>
<p>Setting the editable keyword to True, makes the widget editable.</p>
<p>If you want stripped rows, pass the stripped_rows with a tuple (or list) of two colors.</p>
<p>If you want row numbers, then pass to <em>row_numbers</em> parameter a True value.</p>
<p>These are the extra options for this class:</p>
<ul>
<li>entry_background</li>
<li>entry_foreground</li>
<li>entry_validatecommand</li>
<li>entry_selectbackground</li>
<li>entry_selectborderwidth</li>
<li>entry_selectforeground</li>
<li>scrollbar_background</li>
<li>scrollbar_troughcolor</li>
<li>rowlabel_anchor</li>
<li>rowlabel_minwidth</li>
<li>rowlabel_hoverbackground</li>
<li>frame_relief</li>
<li>frame_borderwidth</li>
<li>frame_background</li>
<li>row_numbers</li>
</ul>
Automatic resized Text widget (Tkinter) (Python)
2016-12-10T15:40:25-08:00Miguel Martínez Lópezhttp://code.activestate.com/recipes/users/4189907/http://code.activestate.com/recipes/578886-automatic-resized-text-widget-tkinter/
<p style="color: grey">
Python
recipe 578886
by <a href="/recipes/users/4189907/">Miguel Martínez López</a>
(<a href="/recipes/tags/autoresize/">autoresize</a>, <a href="/recipes/tags/text/">text</a>, <a href="/recipes/tags/tkinter/">tkinter</a>).
Revision 14.
</p>
<p>The Text widget resize to its contents.
Based on this:
<a href="https://stackoverflow.com/questions/11544187/tkinter-resize-text-to-contents" rel="nofollow">https://stackoverflow.com/questions/11544187/tkinter-resize-text-to-contents</a></p>
<p>But here there is one important improvement:
The widget resize first, before a character inclusion.</p>
<p>For this trick I have had to use tag bindings.</p>
<p>Here there is a practical application of this widget:</p>
<p><a href="https://code.activestate.com/recipes/578885-draggable-desktop-note-or-sticky-notes-in-tkinter/" rel="nofollow">https://code.activestate.com/recipes/578885-draggable-desktop-note-or-sticky-notes-in-tkinter/</a></p>
An Entry with autocompletion for the Tkinter GUI (Python)
2012-09-06T19:16:09-07:00Miguel Ángel Alarcos Torrecillashttp://code.activestate.com/recipes/users/4183471/http://code.activestate.com/recipes/578253-an-entry-with-autocompletion-for-the-tkinter-gui/
<p style="color: grey">
Python
recipe 578253
by <a href="/recipes/users/4183471/">Miguel Ángel Alarcos Torrecillas</a>
(<a href="/recipes/tags/autocomplete/">autocomplete</a>, <a href="/recipes/tags/entry/">entry</a>, <a href="/recipes/tags/tkinter/">tkinter</a>).
Revision 2.
</p>
<p>An example of how to make an entry widget with autocompletion for the Tkinter GUI. It uses regular expression but you can subclass AutocompleteEntry and override the comparison method.</p>
<p>You can use the arrow keys 'up' and 'down' to select an item at the listbox, and the 'right' key to take it to the entry widget.</p>
Tkinter Splash Screen (Python)
2010-06-21T18:09:06-07:00Sunjay Varmahttp://code.activestate.com/recipes/users/4174115/http://code.activestate.com/recipes/577271-tkinter-splash-screen/
<p style="color: grey">
Python
recipe 577271
by <a href="/recipes/users/4174115/">Sunjay Varma</a>
(<a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/screen/">screen</a>, <a href="/recipes/tags/splash/">splash</a>, <a href="/recipes/tags/tkinter/">tkinter</a>).
</p>
<p>I wanted to mess around with the overrideredirect function of the window manager, and ended up making a pretty good Python Tkinter splash screen. :)</p>
<p>Just run it for a demo.</p>
<p>There are instructions and more info in the script</p>
Tkinter Datepicker (like the jQuery UI datepicker) (Python)
2017-06-19T18:22:01-07:00Miguel Martínez Lópezhttp://code.activestate.com/recipes/users/4189907/http://code.activestate.com/recipes/580725-tkinter-datepicker-like-the-jquery-ui-datepicker/
<p style="color: grey">
Python
recipe 580725
by <a href="/recipes/users/4189907/">Miguel Martínez López</a>
(<a href="/recipes/tags/calendar/">calendar</a>, <a href="/recipes/tags/datepicker/">datepicker</a>, <a href="/recipes/tags/megawidget/">megawidget</a>, <a href="/recipes/tags/tkinter/">tkinter</a>).
Revision 18.
</p>
<p>It's based on ttkcalendar.py. But the internals are totally changed.I don't use for example the Treeview widget. I added more features also:</p>
<ul>
<li>On mouse over, the day label changes the background</li>
<li>The selected day has an outstanding style</li>
<li>Added support for many hotkeys</li>
</ul>
<p>These are the default bindings:</p>
<ul>
<li><p><em>Click button 1 on entry:</em> Show calendar</p></li>
<li><p><em>Click button 1 outside entry and calendar:</em> Hide calendar</p></li>
<li><p><em>Escape:</em> Hide calendar</p></li>
<li><p><em>CTRL + PAGE UP:</em> Move to the previous month.</p></li>
<li><p><em>CTRL + PAGE DOWN:</em> Move to the next month.</p></li>
<li><p><em>CTRL + SHIFT + PAGE UP:</em> Move to the previous year.</p></li>
<li><p><em>CTRL + SHIFT + PAGE DOWN:</em> Move to the next year.</p></li>
<li><p><em>CTRL + LEFT:</em> Move to the previous day.</p></li>
<li><p><em>CTRL + RIGHT:</em> Move to the next day.</p></li>
<li><p><em>CTRL + UP:</em> Move to the previous week.</p></li>
<li><p><em>CTRL + DOWN:</em> Move to the next week.</p></li>
<li><p><em>CTRL + END:</em> Close the datepicker and erase the date.</p></li>
<li><p><em>CTRL + HOME:</em> Move to the current month.</p></li>
<li><p><em>CTRL + SPACE:</em> Show date on calendar</p></li>
<li><p><em>CTRL + Return:</em> Set current selection to entry</p></li>
</ul>
Simple drawing tool with Python turtle graphics (Python)
2016-01-27T22:22:01-08:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/580544-simple-drawing-tool-with-python-turtle-graphics/
<p style="color: grey">
Python
recipe 580544
by <a href="/recipes/users/4173351/">Vasudev Ram</a>
(<a href="/recipes/tags/drawing/">drawing</a>, <a href="/recipes/tags/graphics/">graphics</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/python2/">python2</a>, <a href="/recipes/tags/tkinter/">tkinter</a>, <a href="/recipes/tags/turtle/">turtle</a>).
</p>
<p>A simple drawing program that lets you use your keyboard to draw figures on screen, using the turtle graphics module built into Python.</p>
Image background for tkinter (Python)
2017-04-12T19:37:06-07:00Miguel Martínez Lópezhttp://code.activestate.com/recipes/users/4189907/http://code.activestate.com/recipes/580782-image-background-for-tkinter/
<p style="color: grey">
Python
recipe 580782
by <a href="/recipes/users/4189907/">Miguel Martínez López</a>
(<a href="/recipes/tags/background/">background</a>, <a href="/recipes/tags/tkinter/">tkinter</a>).
Revision 3.
</p>
<p>This is only a proof of concept.</p>
<p>In my first example, PIL is required. I use PIL also to draw the text over the background. I use the place geometry manager to position the entry.</p>
<p>In my second example, I use a canvas widget to draw text over image. I also use the canvas to create other widgets over the background.</p>
Tkinter search box (Python)
2017-04-08T12:27:36-07:00Miguel Martínez Lópezhttp://code.activestate.com/recipes/users/4189907/http://code.activestate.com/recipes/580773-tkinter-search-box/
<p style="color: grey">
Python
recipe 580773
by <a href="/recipes/users/4189907/">Miguel Martínez López</a>
(<a href="/recipes/tags/entry/">entry</a>, <a href="/recipes/tags/search/">search</a>, <a href="/recipes/tags/searchbox/">searchbox</a>, <a href="/recipes/tags/tkinter/">tkinter</a>).
Revision 9.
</p>
<p>Instead of using two colors for active background and normal background, I use only one color and opacity parameter.</p>
<p>I trigger the feeling of a button using different colors when the mouse is and isn't over. Many modern HTML search boxes uses the same approach.</p>
<p>Command function receives text of entry box when button is pressed.</p>
Tkinter Animated GIF (Python)
2017-04-10T11:27:05-07:00Miguel Martínez Lópezhttp://code.activestate.com/recipes/users/4189907/http://code.activestate.com/recipes/580708-tkinter-animated-gif/
<p style="color: grey">
Python
recipe 580708
by <a href="/recipes/users/4189907/">Miguel Martínez López</a>
(<a href="/recipes/tags/gif/">gif</a>, <a href="/recipes/tags/tkinter/">tkinter</a>).
Revision 10.
</p>
<p>Tkinter GIF in motion. It uses the "after" command of Tcl and PIL.</p>
<p>Add path to GIF to make the example working.</p>