<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Jorge Louis De Castro napsal(a):
<blockquote cite="midBAY102-DAV1161C9E9554D6F6B227716D7B10@phx.gbl"
 type="cite">
  <meta http-equiv="Content-Type" content="text/html; ">
  <meta content="MSHTML 6.00.2900.2722" name="GENERATOR">
  <style></style>
  <div><font face="Arial" size="2">Hi,</font></div>
  <div>&nbsp;</div>
  <div><font face="Arial" size="2">I have an optionmenu widget that
works just fine except that&nbsp; can't find docs to get hold of events as
they happen, kinda like the command=XYZ of other widgets like buttons.</font></div>
  <div>&nbsp;</div>
  <div><font face="Arial" size="2">The code I'm using for the option
menu is the following:</font></div>
  <div>&nbsp;</div>
  <div><font face="Arial" size="2">OPTIONS =
["en","pt","es","it","fr","de"]<br>
self.startw.variable = StringVar()<br>
self.startw.variable.set(OPTIONS[0]) # default value<br>
self.startw.whis_butt=apply(OptionMenu, (self.startw,
self.startw.variable) + tuple(OPTIONS))<br>
self.startw.whis_butt.grid(column=1, row=3)</font></div>
  <div>&nbsp;</div>
  <div><font face="Arial" size="2">Now I'd like to have a function like:</font></div>
  <div>&nbsp;</div>
  <div><font face="Arial" size="2">def onChange(self):</font></div>
  <div><font face="Arial" size="2">&nbsp;&nbsp;&nbsp;&nbsp; # do optionmenu specific stuff</font></div>
  <div>&nbsp;</div>
  <div><font face="Arial" size="2">but can't find how to do it, how to
associate/bind onChange with the optionmenu widget.</font></div>
  <div><font face="Arial" size="2">Any help will be highly appreciated.</font></div>
  <div>&nbsp;</div>
</blockquote>
This art is called Trace Variable and could be used like this (copied
and rearranged from one of the prevously posted message from here):<br>
<tt><br>
from Tkinter import *<br>
<br>
OPTIONS = [<br>
&nbsp;&nbsp;&nbsp; "egg",<br>
&nbsp;&nbsp;&nbsp; "bunny",<br>
&nbsp;&nbsp;&nbsp; "chicken"<br>
]<br>
<br>
def callbackFunc(name, index, mode):<br>
&nbsp; #print "callback called with name=%r, index=%r, mode=%r" % (name,
index, mode)<br>
&nbsp; varValue = root.getvar(name)<br>
&nbsp; print varValue<br>
&nbsp; # modify the value, just to show it can be done<br>
&nbsp; #root.setvar(name, varValue)<br>
<br>
root = Tk()<br>
var = StringVar()<br>
var.set(OPTIONS[2]) # default value<br>
rememberMe = var.trace_variable('w', callbackFunc)&nbsp;&nbsp; <br>
# var.trace('w', callbackFunc) # this works, too<br>
<br>
<br>
<br>
w = OptionMenu (root, var, *OPTIONS)<br>
w.pack()<br>
<br>
<br>
root.mainloop()<br>
</tt><br>
Hope its what you asked for :-)<br>
<pre class="moz-signature" cols="100">-- 
geon

</pre>
</body>
</html>