On 10/29/08, Olrik Lenstra <o.lenstra@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@gmail.com>
---------- Forwarded message ---------- From: Guilherme Polo <ggpolo@gmail.com> Date: Oct 29, 2008 9:16 AM Subject: Re: [Tkinter-discuss] WxPython -> Tkinter To: Olrik Lenstra <o.lenstra@gmail.com> Cc: python-list@python.org
On 10/29/08, Olrik Lenstra <o.lenstra@gmail.com> wrote:
Hello everyone,
A while ago I joined the Tutor mailing list, and they helped me out
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
with a 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@python.org
http://mail.python.org/mailman/listinfo/tkinter-discuss
-- -- Guilherme H. Polo Goncalves
-- -- Guilherme H. Polo Goncalves
_______________________________________________ Tkinter-discuss mailing list Tkinter-discuss@python.org
-- -- Guilherme H. Polo Goncalves