TK program problem

rantingrick rantingrick at gmail.com
Sun May 22 10:03:29 EDT 2011


On May 21, 7:03 pm, bvdp <b... at mellowood.ca> wrote:
> IIRC, I used the class method since it nicely encapsulates a set of
> operations:
>
>    - create/raise a window
>    - list a set of configurable options
>    - have <cancel> and <save> buttons, both of which destroy the
> window.

Ok NOW we are getting somewhere! It is amazing how helpful people can
be when you explain your problem in "plain English". What you are
describing here is a dialog (be it modal or not). However your earlier
description of...

 """Yes, the class is instantiated when the button is clicked. Then,
the user stays in the class and uses its methods until he hits <close>
in the class. """

... was about as effective as the "orb of confusion" on Patrick...
*drool*

> Having a function as the callback certainly works as well. Not sure
> which is the best method in the long run ... I'm trying to use classes
> more in my programming since it's nice to wrap a bunch of functions up
> like this.

Yes you ABSOLUTELY SHOULD encapsulate the dialog code in a class! THEN
create an instance of the class inside a "easy to call" function.

class MyDialog(blah):
   blah,blah,blah

def show_dialog(*args):
    d = MyDialog(*args)
    return d.result

result = show_dialog()

...and they all lived happily ever after ;-)



More information about the Python-list mailing list