The result data in the seconde frame(panel) doesn't appear exactly

13 views
Skip to first unread message

Hari Coder

unread,
Nov 16, 2016, 10:40:31 AM11/16/16
to wxPython-users
Hi everyone,
Im new to python and if someone can explain to me or can help me in this following code why the data I want to show in the second panel doesn't appear exactly.
The checkbox is not "checkable".

If you try to all run the code , you'll see what I mean.

I've spent so many times , and I'm so tired then I'm sorry for being brief guys.


Thanks.



    import wx
    from wx.lib.pubsub import Publisher

    import sys

    reload(sys)
    sys.setdefaultencoding('cp1252')

    ########################################################################
    class OtherFrame(wx.Frame):
    
        #----------------------------------------------------------------------
       def __init__(self):
            wx.Frame.__init__(self, None, wx.ID_ANY, "Secondary Frame for showing ResulT",size=(400,400))
            self.panel = OtherPanel(self)
           

    class OtherPanel(wx.Panel):
        def __init__(self, parent):
            wx.Panel.__init__(self, parent=parent)
            self.frame = parent
    
    ########################################################################
    class MainPanel(wx.Panel):
        #----------------------------------------------------------------------
        def __init__(self, parent):
            wx.Panel.__init__(self, parent=parent)
            self.frame = parent
            
    
            self.postal_code = wx.TextCtrl(self, value="")
            self.limit = wx.TextCtrl(self,value="")
            showSecondFrame = wx.Button(self, label="Catching")
            showSecondFrame.Bind(wx.EVT_BUTTON, self.ShowFrame)
    
            sizer = wx.BoxSizer(wx.VERTICAL)
            sizer.Add(self.postal_code, 0, wx.ALL|wx.CENTER, 5)
            sizer.Add(self.limit, 0, wx.ALL|wx.CENTER, 10)
            sizer.Add(hideBtn, 0, wx.ALL|wx.CENTER, 5)
            self.SetSizer(sizer)
           
        #----------------------------------------------------------------------
        def ShowFrame(self, event):
            postal_code = self.postal_code.GetValue()
            limit = self.limit.GetValue()
            new_frame = OtherFrame()
            new_frame.Show()
            print limit, postal_code
            Y = 10
            i=0
            all_data = ['Far Away 1337','Street Dance 101','Necro Lover 152','N0stalgene 689']
            for address in all_data:
                Y += 20
                i += 1
               
                self.cb = wx.CheckBox(new_frame, label=str(address+"-"+postal_code+"-"+limit), pos=(10,Y))
              
            
    ########################################################################
    class MainFrame(wx.Frame):
        #----------------------------------------------------------------------
        def __init__(self):
            wx.Frame.__init__(self, None, wx.ID_ANY, "TEST1NG")
            self.panel = MainPanel(self)
            self.new_frame = OtherFrame()
    
    
    #----------------------------------------------------------------------
    if __name__ == "__main__":
        app = wx.App(False)
        frame = MainFrame()
        frame.Show()
        app.MainLoop()



Tim Roberts

unread,
Nov 16, 2016, 1:08:07 PM11/16/16
to wxpytho...@googlegroups.com
Hari Coder wrote:
>
> Im new to python and if someone can explain to me or can help me in
> this following code why the data I want to show in the second panel
> doesn't appear exactly.
> The checkbox is not "checkable".
>
> If you try to all run the code , you'll see what I mean.

Your code does not actually run, because you left a reference to hideBtn
that does not exist.

The problem here is a subtle one. You may have noticed that your
checkboxes were all a different color than the rest of the window.
That's a clue to the problem. In wxWidgets, the usual dialog box
handling (tab navigation and such) is not provided by the frame. It's
provided by a panel. In your case, your second frame is creating a
panel, but you are creating the checkboxes as children of the frame, not
the panel. So, the clicks and keystrokes aren't getting forwarded
properly. If you change this:
self.cb = wx.CheckBox(new_frame,
label=address+"-"+postal_code+"-"+limit, pos=(10,Y))
to this:
self.cb = wx.CheckBox(new_frame.panel,
label=address+"-"+postal_code+"-"+limit, pos=(10,Y))
you'll find that it does what you expect.

By the way, you create an OtherFrame in your MainFrame.__init__, but you
never use it. If you really meant to use that instead of creating a new
OtherFrame each time, then you need to change ShowFrame to use
self.new_frame.other.

Also, in the line I changed above, you are overwriting self.cb every
time you create a new checkbox. You might not need to save them at all,
but if you do, you'll need to create a list, not a single variable.

--
Tim Roberts, ti...@probo.com
Providenza & Boekelheide, Inc.

Reply all
Reply to author
Forward
0 new messages