From: Harry Truax Date: 2012-07-11T21:00:27+09:00 Subject: Re: Help needed with a TK Listbox --20cf307d008aa6203604c48c97f5 Content-Type: text/plain; charset=ISO-8859-1 Thanks! On Wed, Jul 11, 2012 at 3:34 AM, Hidetoshi NAGAI wrote: > From: Harry Truax > Subject: Help needed with a TK Listbox > Date: Wed, 11 Jul 2012 02:24:13 +0900 > Message-ID: < > CAM8KA+Hc5pgV+Q31u_2FthAPCtkEc67GqR0ihr+9xObjD110uw@mail.gmail.com> > > > I have a TK listbox, it is set for selectmode=>"single". All I want to do > > is de-select the selected list item when clicked on. So basically it > would > > toggle between being selected [highlighted in blue on the display] and > not > > selected [no blue highlighting]. I cannot use selectmode=>"multiple", as > > only one item can be selected at a time. I would rather not use a button > > and bind to that either. > > I recommend you to use TkBindTag and Tk.callback_break. > For example, > ------------------------------------------------- > require 'tk' > > lbox = Tk::Listbox.new(:activestyle=>:none).pack(:fill=>:both, > :expand=>true) > lbox.insert :end, *%w(a b c d e f g) > > > btag = TkBindTag.new > lbox.bindtags_unshift btag > > btag.bind('1', :widget, :y){|w, y| > idx = w.nearest y > > if idx == w.curselection[0] > w.selection_clear idx > Tk.callback_break > else > w.selection_set idx > # Tk.callback_continue > end > } > > Tk.mainloop > ------------------------------------------------- > -- > Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) > Department of Artificial Intelligence, Kyushu Institute of Technology > > -- Harry Truax Phone: 315.463.8506 Email: htruax@stf.com 26 Corporate Circle East Syracuse, NY 13057 --20cf307d008aa6203604c48c97f5 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Thanks!

On Wed, Jul 11, 2012 at 3:34 AM, = Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp> wrote:
From: Harry Truax <htruax@stf.com>
Subject: Help needed with a TK Listbox
Date: Wed, 11 Jul 2012 02:24:13 +0900
Message-ID: <CAM8KA+Hc5pgV+Q31u_2FthAPCtkEc67GqR0ihr+9x= ObjD110uw@mail.gmail.com>

> I have a TK listbox, it is set for sele= ctmode=3D>"single". All I want to do
> is de-select the selected list item when clicked on. So basically it w= ould
> toggle between being selected [highlighted in blue on the display] and= not
> selected [no blue highlighting]. I cannot use selectmode=3D>"m= ultiple", as
> only one item can be selected at a time. I would rather not use a butt= on
> and bind to that either.

I recommend you to use TkBind= Tag and Tk.callback_break.
For example,
-------------------------------------------------
require 'tk'

lbox =3D Tk::Listbox.new(:activestyle=3D>:none).pack(:fill=3D>:both, = :expand=3D>true)
lbox.insert :end, *%w(a b c d e f g)


btag =3D TkBindTag.new
lbox.bindtags_unshift btag

btag.bind('1', :widget, :y){|w, y|
=A0 idx =3D w.nearest y

=A0 if idx =3D=3D w.curselection[0]
=A0 =A0 w.selection_clear idx
=A0 =A0 Tk.callback_break
=A0 else
=A0 =A0 w.selection_set idx
=A0 =A0 # Tk.callback_continue
=A0 end
}

Tk.mainloop
-------------------------------------------------
--
Hidetoshi NAGAI (nagai@ai.kyutech= .ac.jp)
Department of Artificial Intelligence, Kyushu Institute of Technology




--
Harry Truax=
Phone: 315.463.8506
Email: htruax@= stf.com
26 Corporate Circle
East Syracuse, NY 13057

--20cf307d008aa6203604c48c97f5--