tkinker:Simulating GUI Button Press

Jeff Epler jepler at unpythonic.net
Wed Jan 8 19:51:44 EST 2003


On Thu, Jan 09, 2003 at 12:40:07AM +0000, Tim Daneliuk wrote:
> Is there a way to programmatically generate the event that acts like
> CmdBtn or DirBtn have been pressed?  I am familiar with keyboard events,
> but cannot seem to figure out how to activate a Menubutton element as if
> it has been clicked by the user...

These classes have an 'invoke' method:
    Button  Checkbutton  Menu  Radiobutton

For whatever reason, Menubutton doesn't (and if you read the Tcl
procedures called by the builtin bindings, they operate by calling
internal Tk procedures, and depend on the type of OS where your program
is running, in the name of "native feel").  However, the tk_popup method
(on menu widgets) can be used to post a menu at the desired position.
It does not handle mouse/keyboard grab entirely like clicking a
menubutton, though.

Jeff





More information about the Python-list mailing list