Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Python

listbox binding..what is the current selection?

 

 

Python python RSS feed   Index | Next | Previous | View Threaded


xer0925 at gmail

Mar 5, 2013, 4:54 PM

Post #1 of 6 (407 views)
Permalink
listbox binding..what is the current selection?

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.


--
http://mail.python.org/mailman/listinfo/python-list


rantingrickjohnson at gmail

Mar 5, 2013, 5:26 PM

Post #2 of 6 (396 views)
Permalink
Re: listbox binding..what is the current selection? [In reply to]

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/pubs/tkinter/web/index.html

--
http://mail.python.org/mailman/listinfo/python-list


xer0925 at gmail

Mar 6, 2013, 8:38 PM

Post #3 of 6 (392 views)
Permalink
Re: listbox binding..what is the current selection? [In reply to]

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.


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/pubs/tkinter/web/index.html
--
http://mail.python.org/mailman/listinfo/python-list


rantingrickjohnson at gmail

Mar 6, 2013, 9:49 PM

Post #4 of 6 (389 views)
Permalink
Re: listbox binding..what is the current selection? [In reply to]

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 docs on 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. (please don'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 more you 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't seem 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 "how to problem solve" is much more important skill than "learning how to solve a 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 the student 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.
--
http://mail.python.org/mailman/listinfo/python-list


wrw at mac

Mar 7, 2013, 7:13 AM

Post #5 of 6 (387 views)
Permalink
Re: listbox binding..what is the current selection? [In reply to]

On Mar 6, 2013, at 11:38 PM, Rex Macey <xer0925 [at] gmail> 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/pubs/tkinter/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
--
http://mail.python.org/mailman/listinfo/python-list


rantingrickjohnson at gmail

Mar 7, 2013, 9:03 AM

Post #6 of 6 (386 views)
Permalink
Re: listbox binding..what is the current selection? [In reply to]

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.
--
http://mail.python.org/mailman/listinfo/python-list

Python python RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.