Tkinter menu widget causes delays in scheduled callbacks
I'm working on a GUI app with tkinter (which I am fairly new to). It's for comparing the clocks on two computers across a network. It uses callbacks (scheduled using the "after" method of the root window) to update text and canvas widgets in a GUI. The canvas widgets are used for dynamic displays, "animated" by the scheduled updates. The root window has a menu widget with some cascade menus. Clicking on the menu and leaving it in 'focus' seems to cause periodic 500+ms delays in the update callbacks. This causes noticeable jerky operation of the widgets whenever the menu has focus. I know that in using the window's after method "Tkinter only guarantees that the callback will not be called earlier than" the time given, but it seems strange that displaying the menu would be expected to cause such disruption (repeatedly). Have I done something wrong in the code that is causing this?
Below is a minimilized version which shows the time it actually took for a scheduled callback of 25ms. Running it on my windows computers, the spikes in delay (500-600ms) are apparent when the menu has focus.
This seems to happen on windows xp and windows 7, but not under kubuntu linux (oneiric).
Is there something I could do to work around this and keep the updates smooth? Any insight would be greatly appreciated!
from Tkinter import *
def __init__(self, master):
self.master = master
# create a toplevel menu
menubar = Menu(self.master)
# create a pulldown menu
main_menu = Menu(menubar, tearoff=0)
#add a command to the pulldown
#add the pulldown to the menu bar
# display the menu
#frame for the text widget
frame = Frame(self.master)
#text widget and scrollbar
self.text_widget = Text(frame)
scroll_bar = Scrollbar(frame)
scroll_bar.pack(side=RIGHT, fill=Y, expand=1)
self.text_widget.pack(fill=BOTH, expand=1, side=RIGHT)
self.last_time = time.time()
def print_text(self, string):
self.text_widget.insert(END, string + "\n")
now = time.time()
self.print_text( "%.2f" % ( (now - self.last_time)*1000 ))
self.last_time = now
root = Tk()
root.geometry("%dx%d%+d%+d" % (600, 400, 0, 0) )
window = AppWindow(root)
Related Article:tkinter text widget help
is a solved Python discussion thread by moroccanplaya that has 2 replies and was last updated 1 year ago.