Top-rated recipes tagged "tkinter" but not "listbox"http://code.activestate.com/recipes/tags/tkinter-listbox/top/2017-05-06T19:06:05-07:00ActiveState Code RecipesPython Tkinter Canvas Rectangle Selection Box (Python)
2010-10-01T02:17:50-07:00Sunjay Varmahttp://code.activestate.com/recipes/users/4174115/http://code.activestate.com/recipes/577409-python-tkinter-canvas-rectangle-selection-box/
<p style="color: grey">
Python
recipe 577409
by <a href="/recipes/users/4174115/">Sunjay Varma</a>
(<a href="/recipes/tags/canvas/">canvas</a>, <a href="/recipes/tags/rectangle/">rectangle</a>, <a href="/recipes/tags/selection/">selection</a>, <a href="/recipes/tags/tkinter/">tkinter</a>).
</p>
<p>A simple, yet effective rectangle selection box. :)</p>
<p>Works with a tkinter canvas! Just add the class and set it up like in the example code. The cross heir was my own touch, the RectTracker only draws a box.</p>
<p>Have fun! And please don't just vote down, post what you don't like if you don't like it.</p>
Tkinter 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>
chatbox megawidget for tkinter (Python)
2017-02-23T22:47:16-08:00Miguel Martínez Lópezhttp://code.activestate.com/recipes/users/4189907/http://code.activestate.com/recipes/580757-chatbox-megawidget-for-tkinter/
<p style="color: grey">
Python
recipe 580757
by <a href="/recipes/users/4189907/">Miguel Martínez López</a>
(<a href="/recipes/tags/chat/">chat</a>, <a href="/recipes/tags/chatbox/">chatbox</a>, <a href="/recipes/tags/tkinter/">tkinter</a>).
Revision 3.
</p>
<p>Chatbox megawidget.</p>
<p>Arguments:</p>
<ul>
<li><p>my_nick</p>
<p>Nick of user chatting</p></li>
<li><p>command</p>
<p>Callback to call when a message is sent</p></li>
<li><p>logging_file</p>
<p>File to log all the messages</p></li>
<li><p>topic</p>
<p>Topic for the chatbox</p></li>
<li><p>maximum_lines</p>
<p>Max lines to show</p></li>
<li><p>entry_controls</p>
<p>Builder of controls for the entry (optional)</p></li>
<li><p>tags</p>
<p>List of tag configurations for the Text widget</p></li>
</ul>
<p>Styling arguments:</p>
<ul>
<li><p>timestamp_template</p></li>
<li><p>scrollbar_background</p></li>
<li><p>scrollbar_troughcolor</p></li>
<li><p>history_background</p></li>
<li><p>history_font</p></li>
<li><p>history_padx</p></li>
<li><p>history_pady</p></li>
<li><p>history_width</p></li>
<li><p>entry_font</p></li>
<li><p>entry_background</p></li>
<li><p>entry_foreground</p></li>
<li><p>label_template</p></li>
<li><p>label_font</p></li>
</ul>
Long processing computation in Tkinter or long-running task (Python)
2017-02-06T18:30:18-08:00Miguel Martínez Lópezhttp://code.activestate.com/recipes/users/4189907/http://code.activestate.com/recipes/580754-long-processing-computation-in-tkinter-or-long-run/
<p style="color: grey">
Python
recipe 580754
by <a href="/recipes/users/4189907/">Miguel Martínez López</a>
(<a href="/recipes/tags/computation/">computation</a>, <a href="/recipes/tags/intensive/">intensive</a>, <a href="/recipes/tags/long/">long</a>, <a href="/recipes/tags/task/">task</a>, <a href="/recipes/tags/tkinter/">tkinter</a>).
Revision 12.
</p>
<p>I provide in this module the function "tk_call_async": It executes a function asynchronously.</p>
<pre class="prettyprint"><code>tk_call_async(window, computation, args=(), kwargs={}, callback=None, polling=100, method=MULTIPROCESSING)
</code></pre>
<p>"tk_call_async" executes the function "computation" asynchronously with the provided "args" and "kwargs" without blocking the tkinter event loop.</p>
<p>If "callback" is provided, it will be called with the result when the computation is finished.</p>
<p>If an exception happens doing the computation, the errback function is called with the exception if this is provided.</p>
<p>"Polling" will be the frequency to poll to check for results.</p>
<p>There is two methods to execute the task: using multiprocessing or using threads.</p>
Tkinter draggable list V2 (Python)
2017-03-03T14:13:14-08:00Miguel Martínez Lópezhttp://code.activestate.com/recipes/users/4189907/http://code.activestate.com/recipes/580748-tkinter-draggable-list-v2/
<p style="color: grey">
Python
recipe 580748
by <a href="/recipes/users/4189907/">Miguel Martínez López</a>
(<a href="/recipes/tags/draggable/">draggable</a>, <a href="/recipes/tags/list/">list</a>, <a href="/recipes/tags/tkinter/">tkinter</a>).
Revision 3.
</p>
<p>This version use tkinter frame instead of ttk frame.</p>
<p>This next link is version 1 (It's the same code but it uses ttk frame):</p>
<p><a href="https://code.activestate.com/recipes/580717-sortable-megawidget-in-tkinter-like-the-sortable-w/" rel="nofollow">https://code.activestate.com/recipes/580717-sortable-megawidget-in-tkinter-like-the-sortable-w/</a></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>
Python Mandelbrot Fractal with Tkinter (Python)
2015-05-06T09:57:27-07:00Antoni Gualhttp://code.activestate.com/recipes/users/4182514/http://code.activestate.com/recipes/579048-python-mandelbrot-fractal-with-tkinter/
<p style="color: grey">
Python
recipe 579048
by <a href="/recipes/users/4182514/">Antoni Gual</a>
(<a href="/recipes/tags/fractal/">fractal</a>, <a href="/recipes/tags/graphics/">graphics</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/tkinter/">tkinter</a>).
Revision 9.
</p>
<p>Displays in a Tk window a pretty coloured 640x480 Mandelbrot set in 6 seconds. Calculates each one of the 300K pixels with a maximum of 256 iterations. <br>
Only Tkinter used. Tested with Python 3.4 <br>
I will test any contribution and add it to the code if worthy.</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>
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>
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>
Stacked frame for Tkinter (Python)
2017-04-13T18:20:26-07:00Miguel Martínez Lópezhttp://code.activestate.com/recipes/users/4189907/http://code.activestate.com/recipes/580784-stacked-frame-for-tkinter/
<p style="color: grey">
Python
recipe 580784
by <a href="/recipes/users/4189907/">Miguel Martínez López</a>
(<a href="/recipes/tags/animation/">animation</a>, <a href="/recipes/tags/frame/">frame</a>, <a href="/recipes/tags/stacked/">stacked</a>, <a href="/recipes/tags/tkinter/">tkinter</a>).
Revision 2.
</p>
<p>I provide here a stacked frame widget with possibility to use animation for the transition.</p>
Metro Checkbuttons and Radiobuttons (Python)
2017-04-12T23:25:49-07:00Miguel Martínez Lópezhttp://code.activestate.com/recipes/users/4189907/http://code.activestate.com/recipes/580783-metro-checkbuttons-and-radiobuttons/
<p style="color: grey">
Python
recipe 580783
by <a href="/recipes/users/4189907/">Miguel Martínez López</a>
(<a href="/recipes/tags/checkbutton/">checkbutton</a>, <a href="/recipes/tags/radiobutton/">radiobutton</a>, <a href="/recipes/tags/tkinter/">tkinter</a>).
Revision 2.
</p>
<p>This recipe shows how to create custom checkbuttons and radiobuttons</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>
Metro Accordion for Tkinter (Python)
2017-04-11T15:52:23-07:00Miguel Martínez Lópezhttp://code.activestate.com/recipes/users/4189907/http://code.activestate.com/recipes/580781-metro-accordion-for-tkinter/
<p style="color: grey">
Python
recipe 580781
by <a href="/recipes/users/4189907/">Miguel Martínez López</a>
(<a href="/recipes/tags/accordion/">accordion</a>, <a href="/recipes/tags/metro/">metro</a>, <a href="/recipes/tags/tkinter/">tkinter</a>, <a href="/recipes/tags/widget/">widget</a>).
Revision 5.
</p>
<p>I provide an animation abstract object to make easy the animation of the accordion.</p>
Metro Dialog for Tkinter (Python)
2017-04-11T11:23:46-07:00Miguel Martínez Lópezhttp://code.activestate.com/recipes/users/4189907/http://code.activestate.com/recipes/580780-metro-dialog-for-tkinter/
<p style="color: grey">
Python
recipe 580780
by <a href="/recipes/users/4189907/">Miguel Martínez López</a>
(<a href="/recipes/tags/dialog/">dialog</a>, <a href="/recipes/tags/metro/">metro</a>, <a href="/recipes/tags/tkinter/">tkinter</a>).
Revision 5.
</p>
<p>I provide here a metro style dialog.</p>
<p>It's possible to use a different style of colors subclassing the class <em>Metro_Dialog</em> or providing the corresponding arguments during class initialization. </p>
<p>For more metro widgets see here:</p>
<p><a href="https://code.activestate.com/recipes/580729-metro-ui-tkinter" rel="nofollow">https://code.activestate.com/recipes/580729-metro-ui-tkinter</a></p>
tkinter custom fonts (Python)
2017-04-10T01:07:11-07:00Miguel Martínez Lópezhttp://code.activestate.com/recipes/users/4189907/http://code.activestate.com/recipes/580778-tkinter-custom-fonts/
<p style="color: grey">
Python
recipe 580778
by <a href="/recipes/users/4189907/">Miguel Martínez López</a>
(<a href="/recipes/tags/font/">font</a>, <a href="/recipes/tags/tkinter/">tkinter</a>).
Revision 2.
</p>
<p>One Windows the best solution is to use the trick explained here:</p>
<p><a href="http://stackoverflow.com/a/30631309" rel="nofollow">http://stackoverflow.com/a/30631309</a></p>
<p>Another possibility is to use PIL. creating an image with the text and a specific font.</p>
<p>I provide 2 classes: <em>CustomFont_Label</em> and <em>CustomFont_Message</em>.</p>
<p><em>CustomFont_Message</em> displays multilines but requires the <em>width</em> parameter.</p>
Metro Spinner for Tkinter (Python)
2017-04-10T21:14:36-07:00Miguel Martínez Lópezhttp://code.activestate.com/recipes/users/4189907/http://code.activestate.com/recipes/580777-metro-spinner-for-tkinter/
<p style="color: grey">
Python
recipe 580777
by <a href="/recipes/users/4189907/">Miguel Martínez López</a>
(<a href="/recipes/tags/canvas/">canvas</a>, <a href="/recipes/tags/image/">image</a>, <a href="/recipes/tags/pil/">pil</a>, <a href="/recipes/tags/rotation/">rotation</a>, <a href="/recipes/tags/spinner/">spinner</a>, <a href="/recipes/tags/tkinter/">tkinter</a>).
</p>
<p>I create a rotating image class <em>RotatingIcon</em> inspired and based on this code:</p>
<p><a href="http://stackoverflow.com/questions/15736530/python-tkinter-rotate-image-animation" rel="nofollow">http://stackoverflow.com/questions/15736530/python-tkinter-rotate-image-animation</a></p>
<p>Features:</p>
<ul>
<li>Methods to stop and start the animation</li>
<li>The animation automically stops when the window is not mapped, and the animation continues when the window is mapped again</li>
<li>Time setting to control the speed of the animation</li>
<li>All the formats accepted for PIL could be used. XBM format is automatically converted to Tk Bitmap. The advantage of Bitmats is the possibility to change the color of the foreground.</li>
</ul>
<p>I added 6 different styles of spinners with different sizes.</p>
<p>I used fontawesome.io for the icon generation.</p>
<p>For more metro widgets see here:</p>
<p><a href="https://code.activestate.com/recipes/580729-metro-ui-tkinter/" rel="nofollow">https://code.activestate.com/recipes/580729-metro-ui-tkinter/</a></p>
Tkinter buddies or shorcuts (Python)
2017-04-07T11:45:19-07:00Miguel Martínez Lópezhttp://code.activestate.com/recipes/users/4189907/http://code.activestate.com/recipes/580775-tkinter-buddies-or-shorcuts/
<p style="color: grey">
Python
recipe 580775
by <a href="/recipes/users/4189907/">Miguel Martínez López</a>
(<a href="/recipes/tags/accelerator/">accelerator</a>, <a href="/recipes/tags/buddies/">buddies</a>, <a href="/recipes/tags/buddy/">buddy</a>, <a href="/recipes/tags/shorcut/">shorcut</a>, <a href="/recipes/tags/tkinter/">tkinter</a>).
Revision 2.
</p>
<p>I provide two convenience functions to create shorcuts. <em>create_buddy</em> creates a buddy for the provided label.A buddy establish a connection between a label and a related widget. It provides a quick keyboard shorcut to focus its partner widget. (Buddy is a terminology used in PyQt).</p>
<p><em>create_shortcut_to_button</em> creates a shorcut to invoke a button.</p>
<p>I bind to toplevel containing the widget. This way, when the dialog is closed all the bindings disappear.</p>
<p>All shorcuts are of this form: Alt + letter</p>
<p>Buddies and shorcuts enriches the user experience providing new ways to navigate and interact quickly with the application.</p>
Tkinter Link or Hyperlink Button (Python)
2017-04-07T11:51:26-07:00Miguel Martínez Lópezhttp://code.activestate.com/recipes/users/4189907/http://code.activestate.com/recipes/580774-tkinter-link-or-hyperlink-button/
<p style="color: grey">
Python
recipe 580774
by <a href="/recipes/users/4189907/">Miguel Martínez López</a>
(<a href="/recipes/tags/button/">button</a>, <a href="/recipes/tags/hyperlink/">hyperlink</a>, <a href="/recipes/tags/link/">link</a>, <a href="/recipes/tags/tkinter/">tkinter</a>, <a href="/recipes/tags/webbrowser/">webbrowser</a>).
Revision 6.
</p>
<p>If a background is not provided, the widget gets the background color from its container. The link button has two states: normal and visited. When the link is clicked, the state change to visited. When the link is clicked the action command is called. By default the text of the link has an underline. There is several options for customization.</p>
<p>I also added this megawidget to my "Metro UI Tkinter" recipe:</p>
<p><a href="https://code.activestate.com/recipes/580729-metro-ui-tkinter" rel="nofollow">https://code.activestate.com/recipes/580729-metro-ui-tkinter</a></p>