<?xml version="1.0" encoding="utf-8"?>
<feed version="0.3" xmlns="http://purl.org/atom/ns#">
<link rel="alternate" type="text/html" href="https://gamma.unpythonic.net/"/>

<title>Jeff Epler's blog</title>
<modified>2024-10-06T14:15:01Z</modified>
<tagline>Photos, electronics, cnc, and more</tagline>
<author><name>Jeff Epler</name><email>jepler@unpythonic.net</email></author>
<entry>
<title>Talking directly to in-process tcl/tk</title>
<issued>2024-10-06T14:15:01Z</issued>
<modified>2024-10-06T14:15:01Z</modified>
<id>https://gamma.unpythonic.net/01728224101</id>
<link rel="alternate" type="text/html" href="https://gamma.unpythonic.net/01728224101"/>
<content type="text/html" mode="escaped">

I recently saw &lt;a href=&quot;https://beauty-of-imagination.blogspot.com/2024/10/simpler-than-pysimplegui-and-python.html&quot;&gt;a post on a blog&lt;/a&gt; about using wish as a subprocess of Python, as a way to access tk without the complexity of tkinter.

&lt;p&gt;To be clear the original post also calls out the situation where the tkinter part of python is not installed by default, and my technique would not be applicable there.

&lt;p&gt;So what do you do if you like Tk but don't care for the high level abstraction provided by Tkinter? Well, you can &lt;tt&gt;import _tkinter&lt;/tt&gt; and create a tkapp object with &lt;tt&gt;_tkinter.create()&lt;/tt&gt;.

&lt;p&gt;The _tkinter module and the tkapp object is largely undocumented, but in Python
3.11 here are some useful methods:
&lt;ul&gt;
&lt;li&gt; tkapp.createcommand: Create a callback into Python code. Takes a string and a callable. Creates a Tcl command with that name, that calls back into Python code: &lt;tt&gt;app.createcomand(&quot;cb&quot;, lambda *args: print(&quot;cb&quot;, args))&lt;/tt&gt;
&lt;li&gt; tkapp.eval: Takes a command and evaluates it. Call it with a single string: &lt;tt&gt;app.eval(&quot;button .b -text HI -command {cb arg1 arg2}&quot;)&lt;/tt&gt;
&lt;li&gt; tkapp.call: Takes a series of arguments, does proper Tcl quoting, and evaluates it: &lt;tt&gt;app.call(&quot;pack&quot;, &quot;.b&quot;)&lt;/tt&gt;
&lt;/ul&gt;
Now, go forth and program your graphical app without all that Python object
nonsense!

&lt;p&gt;&lt;pre&gt;
Python 3.11.2 (main, Aug 26 2024, 07:20:54) [GCC 12.2.0] on linux
Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information.
&gt;&gt;&gt; import _tkinter
&gt;&gt;&gt; app = _tkinter.create()
&gt;&gt;&gt; app.createcommand(&quot;cb&quot;, lambda *args: print(&quot;cb&quot;, args))
&gt;&gt;&gt; app.eval(&quot;button .b -text HI -command {cb arg1 arg2}&quot;)
'.b'
&gt;&gt;&gt; app.call(&quot;pack&quot;, &quot;.b&quot;)
''
&gt;&gt;&gt; # Now I click the button several times ...
&gt;&gt;&gt; cb ('arg1', 'arg2')
cb ('arg1', 'arg2')
cb ('arg1', 'arg2')
&lt;/pre&gt;
</content>
</entry>
<entry>
<title>Setting the NET_WM_ICON for Tkinter application windows</title>
<issued>2005-03-31T02:55:44Z</issued>
<modified>2005-03-31T02:55:44Z</modified>
<id>https://gamma.unpythonic.net/software/01112237744</id>
<link rel="alternate" type="text/html" href="https://gamma.unpythonic.net/software/01112237744"/>
<content type="text/html" mode="escaped">&lt;div style=&quot;float:right;clear:right&quot;&gt;&lt;!-- seticon-example.png--&gt;&lt;div class=albumouter style=width:692.0px id=&gt;&lt;div class=albumimage style=&quot;width:393px;margin-left:149.5px;&quot;&gt;&lt;img src=&quot;https://media.unpythonic.net/emergent-files/software/01112237744/seticon-example.png&quot;&gt;&lt;br&gt;&lt;span&gt;The icon created by the
example program&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;
&lt;/div&gt; This somewhat hackish module can be used to set the
NET_WM_ICON for your Tkinter application.</content>
</entry>
</feed>
