469,643 Members | 2,061 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,643 developers. It's quick & easy.

Re: [Tkinter-discuss] WxPython -> Tkinter

On 10/29/08, Olrik Lenstra <o.*******@gmail.comwrote:
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):

return tk_yield(window, only_if_needed)
for widget, flags in disabled_wins.iteritems():
ttk.Widget.state(widget, flags)
def window_disabler(window):
widgets = window.children.values()

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;


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.
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
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

So is there a similar command for Tkinter as there is for WxPython?

Thanks in advance.

Tkinter-discuss mailing list

-- Guilherme H. Polo Goncalves
Oct 29 '08 #1
0 1481

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

25 posts views Thread by BJörn Lindqvist | last post: by
8 posts views Thread by Erik Johnson | last post: by
5 posts views Thread by Tuvas | last post: by
4 posts views Thread by Anastasios Hatzis | last post: by
2 posts views Thread by Kevin Walzer | last post: by
2 posts views Thread by whatazor | last post: by
8 posts views Thread by Sean DiZazzo | last post: by
reply views Thread by Guilherme Polo | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.