FAQ
Hi Folks,

I have a problem of handling Toplevel window. Basically, I wrote a
listbox viewer with scrollbars, and saved in file listbo.py. Then in
my main GUI window, with menu, I need to launch the listbox viewer, in
a new window. Obviously, a Toplevel window is needed. But, I failed at
passing parameters over to Toplevel window. Please take a look at my
code:

Listbox viewer:
class ScrolledList(Frame):
def __init__(self, options, parent=None):
Frame.__init__(self, parent)
self.pack(expand=YES, fill=BOTH)
self.makeWidgets(options)

In my main GUI:
from XXX import ScrolledList
class Foo:
def __init__(self):
........
def call_listbox(self, params):
new = Toplevel()
alist = ['foor','bar']
ScrolledList(new,alist)

With the code above, the widgets did not show on the Toplevel window,
and the data list ['foo','bar'] did not show up either. Can somebody
help me on it? Thanks a lot!

Muddy Coder

Search Discussions

  • Eric Brunel at Apr 2, 2009 at 7:38 am

    Muddy Coder wrote:
    Hi Folks,

    I have a problem of handling Toplevel window. Basically, I wrote a
    listbox viewer with scrollbars, and saved in file listbo.py. Then in
    my main GUI window, with menu, I need to launch the listbox viewer, in
    a new window. Obviously, a Toplevel window is needed. But, I failed at
    passing parameters over to Toplevel window. Please take a look at my
    code:

    Listbox viewer:
    class ScrolledList(Frame):
    def __init__(self, options, parent=None):
    So the first parameter to the constructor is the scrolled list options, and
    the second one is its parent widget, right?
    Frame.__init__(self, parent)
    self.pack(expand=YES, fill=BOTH)
    self.makeWidgets(options)

    In my main GUI:
    from XXX import ScrolledList
    class Foo:
    def __init__(self):
    ........
    def call_listbox(self, params):
    new = Toplevel()
    alist = ['foor','bar']
    ScrolledList(new,alist)
    So why are you passing the parent widget as first parameter and something else
    as second...?


    On a more general level, unless really needed, I try to avoid creating
    subclasses of exisiting classes with a constructor with completely different
    parameters than the super-class's one. I'm usually doing something like:

    class ScrolledList(Frame):
    def __init__(self, *args, **options):
    Frame.__init__(self, *args, **options)

    The only thing I (rarely...) allow myself to do is to pass custom options and
    getting/removing them with options.pop('my_option') before calling the
    super-class's constructor. Otherwise, I just add specific methods; it's far
    less confusing.

    HTH
    - Eric -
  • Gabriel Genellina at Apr 2, 2009 at 7:55 am
    En Wed, 01 Apr 2009 21:55:52 -0300, Muddy Coder <cosmo_general at yahoo.com>
    escribi?:
    I have a problem of handling Toplevel window. Basically, I wrote a
    listbox viewer with scrollbars, and saved in file listbo.py. Then in
    my main GUI window, with menu, I need to launch the listbox viewer, in
    a new window. Obviously, a Toplevel window is needed. But, I failed at
    passing parameters over to Toplevel window. Please take a look at my
    code:

    Listbox viewer:
    class ScrolledList(Frame):
    def __init__(self, options, parent=None):
    Frame.__init__(self, parent)
    self.pack(expand=YES, fill=BOTH)
    self.makeWidgets(options)

    In my main GUI:
    from XXX import ScrolledList
    class Foo:
    def __init__(self):
    .......
    def call_listbox(self, params):
    new = Toplevel()
    alist = ['foor','bar']
    ScrolledList(new,alist)
    shouldn't the last line be ScrolledList(alist,new)?

    --
    Gabriel Genellina

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedApr 2, '09 at 12:55a
activeApr 2, '09 at 7:55a
posts3
users3
websitepython.org

People

Translate

site design / logo © 2022 Grokbase