Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > TkInter bind() event is not firing event trigger

Reply
Thread Tools

TkInter bind() event is not firing event trigger

 
 
Anthony Papillion
Guest
Posts: n/a
 
      06-23-2010
So I want to execute some code when the user double clicks an item in
a ListBox. The documentation says I should use the listbox.bind()
method, specifying the Double-l event to detect the double left mouse
button click. My code is this:

gsItems = Listbox(root, width=76, height=30, selectmode="browse",
yscroll=scrollBar.set)
gsItems.bind('<Double-l>', openandDisplayFolder)
gsItems.pack()

So the first line configures the Listbox, second line SHOULD set up
the event, and third line, of course, adds the Listbox to the UI.

The problem is that the openandDisplayFolder function is never
executed. The function is VERY simple for now while I learn the way to
do it:

def openandDisplayFolder(event):
tkMessageBox.showinfo("Event Fired", "An item has been double
clicked!")

I've also removed the (event) parameter just in case and tried it and
it makes no difference. What am I doing wrong here?

Thanks!
Anthony
 
Reply With Quote
 
 
 
 
MRAB
Guest
Posts: n/a
 
      06-23-2010
Anthony Papillion wrote:
> So I want to execute some code when the user double clicks an item in
> a ListBox. The documentation says I should use the listbox.bind()
> method, specifying the Double-l event to detect the double left mouse
> button click. My code is this:
>
> gsItems = Listbox(root, width=76, height=30, selectmode="browse",
> yscroll=scrollBar.set)
> gsItems.bind('<Double-l>', openandDisplayFolder)
> gsItems.pack()
>
> So the first line configures the Listbox, second line SHOULD set up
> the event, and third line, of course, adds the Listbox to the UI.
>
> The problem is that the openandDisplayFolder function is never
> executed. The function is VERY simple for now while I learn the way to
> do it:
>
> def openandDisplayFolder(event):
> tkMessageBox.showinfo("Event Fired", "An item has been double
> clicked!")
>
> I've also removed the (event) parameter just in case and tried it and
> it makes no difference. What am I doing wrong here?
>

According to:


http://www.pythonware.com/library/tk...d-bindings.htm

it's '<Double-Button-1>'.
 
Reply With Quote
 
 
 
 
rantingrick
Guest
Posts: n/a
 
      06-23-2010
On Jun 22, 7:21*pm, Anthony Papillion <(E-Mail Removed)> wrote:

> I've also removed the (event) parameter just in case and tried it and
> it makes no difference. What am I doing wrong here?


Well don't remove the event parameter because Tkinter will pass it
every time since this is an EVENT! Here is some code to play with.
Note: If using Python 3.x use lowercase Tkinter!

#-- Start Code --#

import Tkinter as tk
from Tkconstants import *

class MyListbox(tk.Listbox):
def __init__(self, master, **kw):
tk.Listbox.__init__(self, master, **kw)
self.bind("<Double-Button-1>", self.onButtonOneDoubleClick)
self.bind("<Button-3>", self.onButtonThreeClick)

def onButtonOneDoubleClick(self, event):
lineno = self.nearest(event.y)
print 'User double clicked line: %s' %(lineno)

def onButtonThreeClick(self, event):
lineno = self.nearest(event.y)
self.activate(lineno)
#
# You make this next comand a bit smarter
# and only clear the selection when user
# clicks on a line this is not already selected
# (well in multi line mode anyway), but i cannot
# do all the work!
self.selection_clear(0, END)
self.selection_set(lineno)
print 'User right clicked line: %s' %(lineno)


if __name__ == '__main__':
app = tk.Tk()
listbox = MyListbox(app, width=10, height=10, bg='white',
selectmode=EXTENDED)
for x in range(100):
listbox.insert(END, x)
listbox.pack(fill=BOTH, expand=1)
app.mainloop()

#-- End Code --#
 
Reply With Quote
 
rantingrick
Guest
Posts: n/a
 
      06-23-2010
On Jun 22, 7:39*pm, MRAB <(E-Mail Removed)> wrote:

> http://www.pythonware.com/library/tk...events-and-bin...
>
> it's '<Double-Button-1>'.


Yes and i vehemently hate these names! Just hideous if you ask me.

@ Anthony
Also be sure to use an "event name" for an event function/method and
use the docstring to describe what the event will do. Do NOT use the
method name to describe this like you have done. It's also a good idea
to start event methods with "on". This is fairly well recognized as an
event naming convention...

onMotion()
onButtonOneClick()
onKeyPress()
onEnter()
onConfigure()
....etc

....Just ideas folks, just ideas!
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Fileupload not trigger in itemInserting event Tony WONG ASP .Net 0 01-21-2009 04:03 AM
ImageButton does not trigger Repeater.ItemCommand event Nathan Sokalski ASP .Net Web Controls 2 11-17-2007 03:03 AM
ImageButton does not trigger Repeater.ItemCommand event Nathan Sokalski ASP .Net 2 11-17-2007 03:03 AM
Not Able to trigger event in Composite Control King Kong ASP .Net Building Controls 2 12-17-2004 10:59 PM
Button Column added at run time does not seem to trigger SelectIndexChanged Event. Jim Mitchell ASP .Net Datagrid Control 1 08-16-2003 10:16 PM



Advertisments