[Tkinter-discuss] Fwd: WxPython -> Tkinter
Guilherme Polo
ggpolo at gmail.com
Sun Nov 2 14:06:41 CET 2008
On Sun, Nov 2, 2008 at 10:34 AM, Olrik Lenstra <o.lenstra at gmail.com> wrote:
> Hmm, I'm a bit stumped.
> I installed the ttk module and tried applying the code.
> However when I ran my code it gave me an error.
> I thought I might have left a small typo in or something and removed
> the code to check my own.
>
> After I removed the ttk import and code it wouldn't even run my own code again.
> Below is the Traceback:
>
> C:\Users\Olrik Lenstra\Desktop\TroubleShooting Olrik>python TSO.pyw
> Traceback (most recent call last):
> File "TSO.pyw", line 24, in <module>
> import TSOmain
> File "C:\Users\Olrik Lenstra\Desktop\TroubleShooting Olrik\TSOmain.pyw", line
> 79, in <module>
> TSO()
> File "C:\Users\Olrik Lenstra\Desktop\TroubleShooting Olrik\TSOmain.pyw", line
> 37, in TSO
> root = Tk.Tk()
> File "D:\Python25\lib\lib-tk\Tkinter.py", line 1638, in __init__
> self._loadtk()
> File "D:\Python25\lib\site-packages\ttk.py", line 50, in _wrapper
> self.tk.eval('package require tile') # TclError may be raised here
> _tkinter.TclError: can't find package tile
>
You don't have tile installed neither was your tkinter compiled
against tcl/tk 8.5.
Python 2.6 already brings tcl/tk 8.5 and tkinter compiled against them.
Another option is to download tile from:
http://sourceforge.net/project/showfiles.php?group_id=11464&package_id=107795
(get the tile082.zip so you have to do nothing at all). Then unpack
that somewhere. Then you have to set the environment variable
TILE_LIBRARY to the directory where this was unpacked, then you should
be able to run the program with ttk.
You could set this environment var inside your app too:
import os
os.environ['TILE_LIBRARY'] = 'x:/unpacked/tile/here'
import ttk
....
> C:\Users\Olrik Lenstra\Desktop\TroubleShooting Olrik>
>
>
> Regards,
> Olrik
>
> 2008/10/29 Olrik Lenstra <o.lenstra at gmail.com>:
>> So that means that you will use a ttk frame instead of the Tkinter.Frame?
>> I'll see if I can get this working once I get home. (my program is on my
>> Desktop and I just do some testing on my laptop)
>>
>> Thanks a lot so far!
>> Regards,
>> Olrik
>>
>> 2008/10/29 Guilherme Polo <ggpolo at gmail.com>
>>>
>>> On 10/29/08, Olrik Lenstra <o.lenstra at gmail.com> wrote:
>>> > I see, Thanks a lot, I really don't wish to bother you any further, but
>>> > here's my current situation.
>>> > I am still a beginning programmer and I am not entirely sure where to
>>> > put
>>> > this code exactly.
>>> >
>>> > How would I go about using this code?
>>> >
>>>
>>> It should be very similar to what you are already doing in wx.
>>>
>>> But, you would need to layout your toplevel (the one that is created
>>> when you call Tkinter.Tk()) as this:
>>>
>>> There would be a ttk.Frame that would hold all the other widgets,
>>> which should be all ttk widgets according to this sample. Then you
>>> would call safe_yield(frame, True) in the same situations you would in
>>> wx. Now it remains to check if there is the same need for this in tk
>>> as there is in wx.
>>>
>>> Finally, a sample way to layout the widgets:
>>>
>>> root = Tkinter.Tk()
>>> frame = ttk.Frame(root)
>>> btn1 = ttk.Button(frame, text="Button 1")
>>> ...
>>> ... some time later:
>>> safe_yield(frame, True)
>>> ...
>>>
>>> > Thank you so much in advance.
>>> > Regards,
>>> > Olrik
>>> >
>>> > 2008/10/29 Guilherme Polo <ggpolo at gmail.com>
>>> >
>>> > >
>>> > >
>>> > >
>>> > > ---------- Forwarded message ----------
>>> > > From: Guilherme Polo <ggpolo at gmail.com>
>>> > > Date: Oct 29, 2008 9:16 AM
>>> > > Subject: Re: [Tkinter-discuss] WxPython -> Tkinter
>>> > > To: Olrik Lenstra <o.lenstra at gmail.com>
>>> > > Cc: python-list at python.org
>>> > >
>>> > >
>>> > > On 10/29/08, Olrik Lenstra <o.lenstra at gmail.com> wrote:
>>> > > > Hello everyone,
>>> > > >
>>> > > > A while ago I joined the Tutor mailing list, and they helped me out
>>> > with a
>>> > > > question regarding wxPython.
>>> > > > Now however, I have tried a program in Tkinter and I would like to
>>> > > see
>>> > if
>>> > > > there is a similar command to "wx.SafeYield(self, True)".
>>> > >
>>> > >
>>> > > It will be a combination of commands, not a single one. Initially I
>>> > > considered this as "probably without solution", since tcl acquired a
>>> > > yield command just in the 8.6a3 release, but then I looked at
>>> > > wx.SafeYield code and apparently it is possible to replicate it.
>>> > >
>>> > > Here is an initial cut, it is very possible to contain something not
>>> > > equivalent to wx.SafeYield (besides it could be improved):
>>> > >
>>> > >
>>> > > import ttk
>>> > >
>>> > > inside_tkyield = False
>>> > > disabled_wins = {}
>>> > >
>>> > > def safe_yield(window, only_if_needed=False):
>>> > > window_disabler(window)
>>> > >
>>> > > try:
>>> > > return tk_yield(window, only_if_needed)
>>> > > finally:
>>> > > for widget, flags in disabled_wins.iteritems():
>>> > > ttk.Widget.state(widget, flags)
>>> > > disabled_wins.clear()
>>> > >
>>> > >
>>> > > def window_disabler(window):
>>> > > widgets = window.children.values()
>>> > > widgets.append(window)
>>> > >
>>> > > for widget in widgets:
>>> > > if widget.instate(['!disabled']):
>>> > > prev_flags = widget.state(['disabled'])
>>> > > disabled_wins[widget] = prev_flags
>>> > >
>>> > >
>>> > > def tk_yield(window, only_if_needed=False):
>>> > > # wx implements this differently based on the backend it is using
>>> > > global inside_tkyield
>>> > > if inside_tkyield:
>>> > > if not only_if_needed:
>>> > > raise RuntimeError("safe_yield called recursively")
>>> > >
>>> > > return False
>>> > >
>>> > > inside_tkyield = True;
>>> > >
>>> > > window.update()
>>> > > window.update_idletasks()
>>> > >
>>> > > inside_tkyield = False;
>>> > >
>>> > > return True
>>> > >
>>> > >
>>> > > Note that this depends on ttk widgets
>>> > > (http://pypi.python.org/pypi/pyttk) since it uses
>>> > widget.state to
>>> > > disable and reenable the widgets. On windows the "wm" command
>>> > > supports
>>> > > disabling the entire window, so it is easier if you can use it.
>>> > >
>>> > > [Forwarded because I sent to the wrong list first time]
>>> > >
>>> > >
>>> > > > Below is a copy of the message to the tutor list.
>>> > > >
>>> > > > > Dear Mailing list,
>>> > > > >
>>> > > > > a while ago a few of you helped me solve an issue I had with a
>>> > > GUI /
>>> > scan
>>> > > > > program that I made.
>>> > > > > The problem was that when I tried to move the frame it would hang
>>> > until
>>> > > > the
>>> > > > > scan was finished.
>>> > > > > To solve this I had to add "wx.SafeYield(self, True)" to the scan
>>> > > and
>>> > the
>>> > > > > GUI wouldn't hang any more.
>>> > > > > Now I have redone the program and have written it with Tkinter
>>> > instead of
>>> > > > > WxPython.
>>> > > > >
>>> > > > > So is there a similar command for Tkinter as there is for
>>> > > WxPython?
>>> > > > >
>>> > > > > Thanks in advance.
>>> > > > > Regards,
>>> > > > > Olrik
>>> > > > >
>>> > > >
>>> > >
>>> > > > _______________________________________________
>>> > > > Tkinter-discuss mailing list
>>> > > > Tkinter-discuss at python.org
>>> > > >
>>> > http://mail.python.org/mailman/listinfo/tkinter-discuss
>>> > > >
>>> > > >
>>> > >
>>> > >
>>> > >
>>> > > --
>>> > > -- Guilherme H. Polo Goncalves
>>> > >
>>> > >
>>> > > --
>>> > > -- Guilherme H. Polo Goncalves
>>> > >
>>> > >
>>> > >
>>> > > _______________________________________________
>>> > > Tkinter-discuss mailing list
>>> > > Tkinter-discuss at python.org
>>> > >
>>> > http://mail.python.org/mailman/listinfo/tkinter-discuss
>>> > >
>>> >
>>> >
>>>
>>>
>>> --
>>> -- Guilherme H. Polo Goncalves
>>
>>
>
--
-- Guilherme H. Polo Goncalves
More information about the Tkinter-discuss
mailing list