[Tkinter-discuss] Tkinter-discuss Digest, Vol 74, Issue 2

Cameron Laird Cameron at phaseit.net
Fri Apr 2 21:20:39 CEST 2010


On Fri, Apr 02, 2010 at 09:02:15PM +0200, Michael Lange wrote:
			.
			.
			.
> > But tell me, why I can't use two instances of Tk? The way I saw this,
> > was that I was just creating a new object, so I don't understand what
> > is the problem in creating a second object of Tk. I know it doesn't
> > work, but I will like to understand why.
> > 
> 
> I will try to explain, though I am not a no.1 expert :)
> 
> The Tk() window is not just a widget, like a Button or a Toplevel, but
> has its own associated Tcl interpreter which is controlled through
> Python; so if you have two Tk instances in your application, you have
> two different Tcl interpreters running.
> As you noticed in your first code example, this did work, but not
> exactly as you expected. The reason is that the two Tcl interpreters
> cause some unwanted side effects, because they can coexist, but not
> interact; for example, (IIRC) you created two IntVars, but IntVar2
> inside the second Tcl interpreter, which will not work when trying to
> use it as textvariable for a Label belonging to Tcl interpreter #1 ; if
> the application becomes more complex, it will obviously become hard to
> avoid running into traps like this, when OTOH there is not really a
> benefit from the second Tk() window.
> 
> I hope this helps
			.
			.
			.
Worse, each Tk() instance opens a "graphical context", and
*their* behavior isn't well-defined beyond one-per-process.


More information about the Tkinter-discuss mailing list