Latest recipes tagged "tkinter" but not "file"http://code.activestate.com/recipes/tags/tkinter-file/new/2017-05-06T19:06:05-07:00ActiveState Code RecipesTkinter 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>
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 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>
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>
Metro Listbox (Python)
2017-04-16T16:48:22-07:00Miguel Martínez Lópezhttp://code.activestate.com/recipes/users/4189907/http://code.activestate.com/recipes/580785-metro-listbox/
<p style="color: grey">
Python
recipe 580785
by <a href="/recipes/users/4189907/">Miguel Martínez López</a>
(<a href="/recipes/tags/listbox/">listbox</a>, <a href="/recipes/tags/metro/">metro</a>, <a href="/recipes/tags/tkinter/">tkinter</a>).
Revision 2.
</p>
<p>I provide an alternative listbox for tkinter.</p>
<p>Using this trick you can add horizontal and vertical padding to every item and also a width.</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>
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>
Combobox Autocomplete (Python)
2017-04-03T15:17:26-07:00Miguel Martínez Lópezhttp://code.activestate.com/recipes/users/4189907/http://code.activestate.com/recipes/580770-combobox-autocomplete/
<p style="color: grey">
Python
recipe 580770
by <a href="/recipes/users/4189907/">Miguel Martínez López</a>
(<a href="/recipes/tags/autocomplete/">autocomplete</a>, <a href="/recipes/tags/combobox/">combobox</a>, <a href="/recipes/tags/entry/">entry</a>, <a href="/recipes/tags/tkinter/">tkinter</a>).
Revision 11.
</p>
<p>This is my own version of combobox autocomplete. The user can customize the matching function setting whether he wants to ignore case or whether the matching function should only match from the beginning of the string. The other possibility is to provide your own "auto complete function". The complete function returns all the found strings matching the text in the entry box.</p>
<p>It's also possible to customize the height of listbox and whether to use horizontal or vertical scrollbars.</p>
<p>Use arrows or Contro+n, Control+p to move selection on listbox.</p>
<p>This is a practical application of the combobox widget:</p>
<p><a href="https://code.activestate.com/recipes/580771-tkinter-file-autocomplete-entry/" rel="nofollow">https://code.activestate.com/recipes/580771-tkinter-file-autocomplete-entry/</a></p>
Tkinter Desktop Notifications or Popups (Python)
2017-04-01T19:27:59-07:00Miguel Martínez Lópezhttp://code.activestate.com/recipes/users/4189907/http://code.activestate.com/recipes/580769-tkinter-desktop-notifications-or-popups/
<p style="color: grey">
Python
recipe 580769
by <a href="/recipes/users/4189907/">Miguel Martínez López</a>
(<a href="/recipes/tags/alert/">alert</a>, <a href="/recipes/tags/easing/">easing</a>, <a href="/recipes/tags/notification/">notification</a>, <a href="/recipes/tags/popup/">popup</a>, <a href="/recipes/tags/tkinter/">tkinter</a>).
Revision 2.
</p>
<p>This trick requires <em>pytweening</em>:</p>
<p><a href="https://pypi.python.org/pypi/PyTweening" rel="nofollow">https://pypi.python.org/pypi/PyTweening</a></p>
<p>Install writing:</p>
<pre class="prettyprint"><code> pip install pytweening
</code></pre>
<p>It shows a notification on one corner of the screen,and gradually the notification disappears using an easing function. By default, it uses a linear easing function.</p>
<p>The class <em>Notification_Manager</em> has the method <em>create_notification</em>, but it also has some convenient methods to create easily some kind of notifications: success, alert, info, warning.</p>
Tkinter entry with placeholder (Python)
2017-04-06T14:21:03-07:00Miguel Martínez Lópezhttp://code.activestate.com/recipes/users/4189907/http://code.activestate.com/recipes/580768-tkinter-entry-with-placeholder/
<p style="color: grey">
Python
recipe 580768
by <a href="/recipes/users/4189907/">Miguel Martínez López</a>
(<a href="/recipes/tags/entry/">entry</a>, <a href="/recipes/tags/placeholder/">placeholder</a>, <a href="/recipes/tags/tkinter/">tkinter</a>).
Revision 8.
</p>
<p>The function <em>add_placeholder_to</em> adds a placeholder to a tkinter entry.</p>
<p>Parameters:</p>
<ul>
<li><em>entry:</em> Tkinter widget to add placeholder</li>
<li><em>placeholder:</em> Text of placeholder</li>
<li><em>color:</em> Color of placeholder (optional)</li>
<li><em>font</em>: Font of placeholder (optional)</li>
</ul>
<p>A placeholder state object is attached to attribute "placeholder_state" of entry widget for future reference. It makes more easier to configure state of placeholder, or change the preferences of the user for color and font for the placeholder.</p>
<p>This widget is added also to my Metro 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>