Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > listbox binding..what is the current selection?

Reply
Thread Tools

listbox binding..what is the current selection?

 
 
Rex Macey
Guest
Posts: n/a
 
      03-06-2013
I have a listbox with two strings "Fixed" and "Random". It is bound by the following statement:
lbLengthtype.bind('<ButtonRelease-1>',set_lengthtype)

Here's the beginning of the set_lengthtype code:

def set_lengthtype(event=None):
s=lbLengthtype.get(tk.ACTIVE)
print(s)
.....

The print(s) statement is for debugging. If 'Random' was selected and the user clicks 'Fixed', then Random will print. I would like to know what the user just selected, not what was selected before the user clicked. How can I determine the current selection? Thanks.


 
Reply With Quote
 
 
 
 
Rick Johnson
Guest
Posts: n/a
 
      03-06-2013
On Tuesday, March 5, 2013 6:54:45 PM UTC-6, Rex Macey wrote:
> I have a listbox with two strings "Fixed" and "Random".
> [...] Here's the beginning of the set_lengthtype code:
>
> def set_lengthtype(event=None):
> s=lbLengthtype.get(tk.ACTIVE)
> print(s)
> .....
>
> The print(s) statement is for debugging. If 'Random' was
> selected and the user clicks 'Fixed', then Random will
> print. I would like to know what the user just selected,
> not what was selected before the user clicked. How can I
> determine the current selection? Thanks.


Use "listbox.nearest(event.y)" instead of "get(ACTIVE"). And maybe you should spend some time reading the docs eh?

http://infohost.nmt.edu/tcc/help/pub...web/index.html

 
Reply With Quote
 
 
 
 
Rex Macey
Guest
Posts: n/a
 
      03-07-2013
Thanks. I have spent time with the docs, at least with the Python v3.3 andtkinter v8.5 (pdf). I wish they had more examples. My approach is to browse the docs, try a program, fail, read the docs, try again. When I can't figure it out, I post. I appreciate the help.


On Tuesday, March 5, 2013 8:26:12 PM UTC-5, Rick Johnson wrote:
> On Tuesday, March 5, 2013 6:54:45 PM UTC-6, Rex Macey wrote:
>
> > I have a listbox with two strings "Fixed" and "Random".

>
> > [...] Here's the beginning of the set_lengthtype code:

>
> >

>
> > def set_lengthtype(event=None):

>
> > s=lbLengthtype.get(tk.ACTIVE)

>
> > print(s)

>
> > .....

>
> >

>
> > The print(s) statement is for debugging. If 'Random' was

>
> > selected and the user clicks 'Fixed', then Random will

>
> > print. I would like to know what the user just selected,

>
> > not what was selected before the user clicked. How can I

>
> > determine the current selection? Thanks.

>
>
>
> Use "listbox.nearest(event.y)" instead of "get(ACTIVE"). And maybe you should spend some time reading the docs eh?
>
>
>
> http://infohost.nmt.edu/tcc/help/pub...web/index.html

 
Reply With Quote
 
Rick Johnson
Guest
Posts: n/a
 
      03-07-2013
On Wednesday, March 6, 2013 10:38:22 PM UTC-6, Rex Macey wrote:
> I have spent time with the docs, at least with the Python
> v3.3 and tkinter v8.5 (pdf).


Could you post links to the documents you are reading please?

Actually when i said "read the docs" i did not mean the offical Python docson Tkinter (because, IMHO, they are woefully inadequate). I actually meant"read some online tutorials".

The link i gave you is really more of a reference than a tutorial. It's my go-to reference when i can't remember the behavior of "this" or "that" method, or the spelling of "this" or "that" event sequence. Here is another link that is much more of a tutorial.

http://effbot.org/tkinterbook/tkinter-whats-tkinter.htm

> I wish they had more examples.


Yes me too! Examples speak much louder than mere words. Of course, ONLY if the examples are good examples. Maybe we could combine my ability to write good examples with your ability to judge the noob worthiness of such examples and contribute something positive to this community of ingrates. (pleasedon't mis-interpret the theatrical verbiage, i am, in fact, quite serious)

> My approach is to browse the docs, try a program, fail,
> read the docs, try again. When I can't figure it out, I
> post.


That's a wise and considerate path. Considerate both for yourself and others.

================================================== ==========
The path to enlightenment
================================================== ==========
The temptation to run and ask somebody for an answer is *VERY*, well, tempting. The problem is, the more you ask and receive *easy* answers, the moreyou become dependent on your teacher and not yourself.

Luckily for me (although i was unaware of the benefit at the time) i was oblivious to online help forms when i learned programming; forcing me to be self-reliant when learning. It was just me, some badly written docs, and a text editor.

After lots of trial and error and many a smashed keyboard, i emerged from under my rock with a deep knowledge that i don't believe i could have attained by having someone spoon feed me the answers.

It seems that when you *DO* find yourself in a wet paper bag that you can'tseem to mentally punch yourself out of, and you are forced to get outside input, the last thing you need is people "gift wrapping" answers for you.

A wise teacher will give you a few clues and then aim you in the correct direction, leaving you to find the exact path to enlightenment. Learning "howto problem solve" is much more important skill than "learning how to solvea problem"; the old "teach a man to fish..." thing.

================================================== ==========
Request for your personal experiences:
================================================== ==========

Since you are new to Tkinter i wonder if you can give some insights into the specific troubles you are encountering. I have long since forgotten most of the troubles i experienced. This would be a good chance to document the issues with the documents.

================================================== ==========
Learning GUI's cuts you twice!
================================================== ==========

Learning GUI's for the first time is very difficult because before you can learn the API of the current GUI library, you must first learn what a "EditText" is, and what a "StaticText" is, and a "ProgressBar", and a "NoteBook", and abstract things like "InputEvents", and how to bind "inputEvents", and "GeometryManagment"; and blah, blah, blah.

This first step is where most GUI tutorials fail. They try to present both the widgets AND the code to control them simultaneously. It's no wonder thestudent becomes bewildered!

I believe the first step should involve NO code or even code examples. The first step should be mainly a visual experience combined with interactive delving into the intricacies of what "actions" each widget will expose; using only natural language and visuals to describe the actions.

But even when GUI tuts follow this wise progression they fail to utilize the power of visualization, and instead focus on pages and pages of boring text.

The second step is learning the actual methods of the widgets and how to link code to actions.

================================================== ==========
Morals of My Experience:
================================================== ==========

Looking back i believe the Tkinter learning path is flawed in to general ways.

1. The official docs are woefully inadequate.

Which could be solved by writing better documentation, or simply, by linking to a few of the existing good outside documentation. The two links i posted offer the best of both worlds (reference and tutorial[1]) But then, there are all the issues of poor examples around the web. I found myself being thrown into fits of confusion by reading documentations or tutorials that seemed to conflict with one another.

"""Misleading documentation can be more devastating than missing documentation."""

2. The Tkinter API is asinine, inconsistent, and full of multiplicities.

I know that sounds unfair but it *IS* true. Yes, Tkinter is one of the simplest Python GUI's to learn, and it has the benefit of being in the Python stdlib, however, it has many issues[2] that should have been resolved long ago, and could be resolved today if i could convince the "keepers of the source" to engage in healthy discussion of these specifics.

================================================== ==========
REFERENCES:
================================================== ==========
[1] Although the tutorial site has a few confusing examples and fails to cover the new ttk widgets.

[2] Plus, it is missing simple functionalities like "auto-scrollbars". (although this is a direct result of being a slave to the Tk:TCL folks.
 
Reply With Quote
 
William Ray Wing
Guest
Posts: n/a
 
      03-07-2013
On Mar 6, 2013, at 11:38 PM, Rex Macey <> wrote:

> Thanks. I have spent time with the docs, at least with the Python v3.3 and tkinter v8.5 (pdf). I wish they had more examples. My approach is to browse the docs, try a program, fail, read the docs, try again. When I can't figure it out, I post. I appreciate the help.
>
>


With apologies for jumping into the middle of this discussion, but I've found the most helpful tkinter v8.5 docs to be the set at New Mexico tech:

http://infohost.nmt.edu/tcc/help/pub...web/index.html

Seem quite complete and in particular, starting at section 28, they are quite detailed in their explanation of the ttk themed widgets.

-Bill
 
Reply With Quote
 
Rick Johnson
Guest
Posts: n/a
 
      03-07-2013
On Thursday, March 7, 2013 9:13:16 AM UTC-6, William Ray Wing wrote:
> With apologies for jumping into the middle of this
> discussion, but I've found the most helpful tkinter v8.5
> docs to be the set at New Mexico tech:


Well these are free and open forums the last time i checked. Don't worry, nobody is going to get upset because you offered your opinions. I mean, the worst think that could happen is if someone offers up the exact same information that had already been offered early in the thread because they were too lazy to read the thread in full, and now they look like a complete boob ( a helpful boob, but a boob none-the-less). But that's just a "crazy" hypothetical situation. You would never do that. So no need to worry.
 
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
Listbox selection to populate another listbox? Chris Kettenbach ASP .Net 3 06-16-2005 09:19 PM
Listbox item added with client scripts not submitting with ASP:Listbox Simon Prince ASP .Net 2 10-19-2004 04:11 PM
How do I move all items in a listbox to another listbox kent ASP .Net 1 05-03-2004 12:17 AM
click listbox and refresh another listbox DC Gringo ASP .Net 0 04-06-2004 02:13 AM
Re: now desparate! - 1st listbox contents disappears when 2nd listbox appears? blenderdude ASP .Net 0 08-03-2003 10:18 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57