problem extending tkSimpleDialog.Dialog

Discussion in 'Python' started by William Gill, Aug 12, 2005.

  1. William Gill

    William Gill Guest

    I have created a widget that extends Frame() and contains labels,
    checkboxes, and entrys. I am trying to use tkSimpleDialog.Dialog to
    create a modal display of this widget, but am running into some
    (addressing) problems. My widget displays in the parent widget, not the
    tkSimpleDialog.Dialog? I hope this snippet is enough to help, as my
    actual code is really too hard to follow.

    class showtestWidget(tkSimpleDialog.Dialog):
    def body(self,master):
    Label(master,text="showPhoneNums").grid()
    testWidget(self).grid()

    class testWidget(Frame):
    def __init__(self, master):
    Frame.__init__(self)
    self.createWidgets()
    def createWidgets(self):
    Label(self,text="testWidget").grid()

    When the parent script instantiates showtestWidget() it should create a
    transient dialog containing a label with the text "showPhoneNums". It
    does, but the label containing the text "testWidget" is being created in
    the parent widget, not the dialog.

    It seems obvious to me that I'm addressing the wrong parent somehow,
    since the label (probably the testWidget) is being created, but in the
    wrong place.

    I tried changing testWidget(self).grid() to
    testWidget(master).grid(), just to see if that helped, but it made no
    difference.

    Can someone show me where I went wrong?

    Bill
     
    William Gill, Aug 12, 2005
    #1
    1. Advertising

  2. William Gill

    William Gill Guest

    I'm still hammering away, and have found that when I change:

    class testWidget(Frame):
    def __init__(self, master):
    Frame.__init__(self)
    self.createWidgets()
    def createWidgets(self):
    Label(self,text="testWidget").grid()
    to:
    def __init__(self, master):
    Frame.__init__(self)
    self.x=master
    self.createWidgets()
    def createWidgets(self):
    Label(self.x,text="testWidget").grid()

    It seems to work correctly. However my actual widget, an extended Frame
    widget, still doesn't work correctly. This seems to confirm what I
    thought about addressing the correct parent, but I still haven't figured
    it out completely.

    Unless someone can give me a clue, I guess I can keep modifying
    testWidget(Frame) to add the components of my original until I can see
    where it breaks down. On the surface it looks like I'm not passing the
    correct master reference to my frame.

    Bill


    William Gill wrote:
    > I have created a widget that extends Frame() and contains labels,
    > checkboxes, and entrys. I am trying to use tkSimpleDialog.Dialog to
    > create a modal display of this widget, but am running into some
    > (addressing) problems. My widget displays in the parent widget, not the
    > tkSimpleDialog.Dialog? I hope this snippet is enough to help, as my
    > actual code is really too hard to follow.
    >
    > class showtestWidget(tkSimpleDialog.Dialog):
    > def body(self,master):
    > Label(master,text="showPhoneNums").grid()
    > testWidget(self).grid()
    >
    > class testWidget(Frame):
    > def __init__(self, master):
    > Frame.__init__(self)
    > self.createWidgets()
    > def createWidgets(self):
    > Label(self,text="testWidget").grid()
    >
    > When the parent script instantiates showtestWidget() it should create a
    > transient dialog containing a label with the text "showPhoneNums". It
    > does, but the label containing the text "testWidget" is being created in
    > the parent widget, not the dialog.
    >
    > It seems obvious to me that I'm addressing the wrong parent somehow,
    > since the label (probably the testWidget) is being created, but in the
    > wrong place.
    >
    > I tried changing testWidget(self).grid() to testWidget(master).grid(),
    > just to see if that helped, but it made no difference.
    >
    > Can someone show me where I went wrong?
    >
    > Bill
    >
    >
     
    William Gill, Aug 12, 2005
    #2
    1. Advertising

  3. William Gill

    William Gill Guest

    Problem solved. I was not properly passing the master widget reference
    in my frame classes

    class MyWidget(Frame):
    def __init__(self, master, columns,rows, trace_write=None):
    Frame.__init__(self) #<<<< here's my mistake
    ...
    ...
    ...

    should have been:

    class MyWidget(Frame):
    def __init__(self, master, columns,rows, trace_write=None):
    Frame.__init__(self,master)
    ...
    ...
    ...


    Bill

    P.S. I haven't been working on this since my last post. I had to quit
    to go see my oldest graduate.

    William Gill wrote:
    > I have created a widget that extends Frame() and contains labels,
    > checkboxes, and entrys. I am trying to use tkSimpleDialog.Dialog to
    > create a modal display of this widget, but am running into some
    > (addressing) problems. My widget displays in the parent widget, not the
    > tkSimpleDialog.Dialog? I hope this snippet is enough to help, as my
    > actual code is really too hard to follow.
    >
    > class showtestWidget(tkSimpleDialog.Dialog):
    > def body(self,master):
    > Label(master,text="showPhoneNums").grid()
    > testWidget(self).grid()
    >
    > class testWidget(Frame):
    > def __init__(self, master):
    > Frame.__init__(self)
    > self.createWidgets()
    > def createWidgets(self):
    > Label(self,text="testWidget").grid()
    >
    > When the parent script instantiates showtestWidget() it should create a
    > transient dialog containing a label with the text "showPhoneNums". It
    > does, but the label containing the text "testWidget" is being created in
    > the parent widget, not the dialog.
    >
    > It seems obvious to me that I'm addressing the wrong parent somehow,
    > since the label (probably the testWidget) is being created, but in the
    > wrong place.
    >
    > I tried changing testWidget(self).grid() to testWidget(master).grid(),
    > just to see if that helped, but it made no difference.
    >
    > Can someone show me where I went wrong?
    >
    > Bill
    >
    >
     
    William Gill, Aug 13, 2005
    #3
    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. Gheorghe Postelnicu

    tkSimpleDialog fails

    Gheorghe Postelnicu, Aug 31, 2006, in forum: Python
    Replies:
    0
    Views:
    377
    Gheorghe Postelnicu
    Aug 31, 2006
  2. Richard Maher
    Replies:
    10
    Views:
    584
    =?ISO-8859-1?Q?Arne_Vajh=F8j?=
    Feb 9, 2007
  3. inkhorn
    Replies:
    1
    Views:
    627
    inkhorn
    Feb 5, 2009
  4. Matt H
    Replies:
    1
    Views:
    414
    rantingrick
    Apr 4, 2011
  5. rantingrick

    RFC: tkSimpleDialog IMPROVED AGAIN!.

    rantingrick, Jul 3, 2011, in forum: Python
    Replies:
    1
    Views:
    343
    rantingrick
    Jul 4, 2011
Loading...

Share This Page