listbox binding..what is the current selection?

Discussion in 'Python' started by Rex Macey, Mar 6, 2013.

  1. Rex Macey

    Rex Macey Guest

    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.
    Rex Macey, Mar 6, 2013
    #1
    1. Advertising

  2. Rex Macey

    Rick Johnson Guest

    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
    Rick Johnson, Mar 6, 2013
    #2
    1. Advertising

  3. Rex Macey

    Rex Macey Guest

    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/pubs/tkinter/web/index.html
    Rex Macey, Mar 7, 2013
    #3
  4. Rex Macey

    Rick Johnson Guest

    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.
    Rick Johnson, Mar 7, 2013
    #4
  5. 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/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
    William Ray Wing, Mar 7, 2013
    #5
  6. Rex Macey

    Rick Johnson Guest

    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.
    Rick Johnson, Mar 7, 2013
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chris Kettenbach

    Listbox selection to populate another listbox?

    Chris Kettenbach, Jun 15, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    1,650
    Chris Kettenbach
    Jun 16, 2005
  2. Simon Niederberger
    Replies:
    2
    Views:
    16,503
    Christian Kaufhold
    Jan 7, 2005
  3. Andrew Crowe
    Replies:
    1
    Views:
    4,463
    Andrew Crowe
    Sep 13, 2004
  4. curiousity

    HOWTO autopost the selection list upon selection

    curiousity, Nov 21, 2003, in forum: ASP .Net Mobile
    Replies:
    0
    Views:
    269
    curiousity
    Nov 21, 2003
  5. Loebb
    Replies:
    0
    Views:
    202
    Loebb
    Feb 23, 2004
Loading...

Share This Page