Newbie wxPython questions.

Discussion in 'Python' started by nuffnough@gmail.com, Apr 7, 2006.

  1. Guest

    I am running through the wxPython guide and docs and extrapolating
    enough to get confused.

    BAsed on the tute in the getting started wiki I created a panel that
    has most of the elements I want; some check boxes and a couple of
    buttons. The button I have is a simple thing that is supposed to just
    close (destroy) the app. Only thing is, it destroys the panel and
    leaves the app behind. I have attempted to place this on teh frame by
    defining a frame; the button works great and closes the app, but
    because it isn't part of the panel, the panel is all squished up into
    the very top left corner and all you can see is the first checkbox,
    which you can't even check. Can I make a button on the panel destroy
    the frame?

    The next question I have is about adding a second button to the panel
    (or frame, I guess) that will then execute a bunch of things depending
    on which checkboxes are ticked. My attempts to add the button have
    been wrong so far, as you'll see with my code.

    The first code block is my panel only app. The second is how it looks
    after I defined the Frame first and then moved the Cancel button.

    TIA

    Nuffnough



    --

    import wx, sys, os
    class Form1(wx.Panel):
    def __init__(self, parent, id):
    wx.Panel.__init__(self, parent, id)
    self.quote = wx.StaticText(self, -1, "Launching
    :",wx.Point(20,30))

    st = wx.StaticText(self, -1, "Select the applications you need
    to launch:")#, (10, 10)

    cb1 = wx.CheckBox(self, -1, "Read Calander, Check
    Email")#,(65,40), (150, 20), wx.NO_BORDER)
    cb2 = wx.CheckBox(self, -1, "Internet Browser")

    self.Bind(wx.EVT_CHECKBOX, self.EvtCheckBox, cb1)
    self.Bind(wx.EVT_CHECKBOX, self.EvtCheckBox, cb2)
    sizer = wx.BoxSizer(wx.VERTICAL)
    sizer.AddMany( [ cb1,
    cb2,
    ])

    border = wx.BoxSizer(wx.VERTICAL)
    border.Add(st, 0, wx.ALL, 15)
    border.Add(sizer, 0, wx.LEFT, 50)
    self.SetSizer(border)

    pos = cb2.GetPosition().x + cb2.GetSize().width + 25
    btn0 = wx.Button(self, -1, "Cancel", (pos, 150))
    self.Bind(wx.EVT_BUTTON, self.OnCloseMe, btn0)
    self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)

    ''' Commented out btn1 cause I couldn't make it work
    btn1 = wx.Button(self, -1, "Open Apps", (pos + 60, 150))
    self.Bind(wx.EVT_BUTTON, self.OnTestButton, btn1)
    '''

    def EvtCheckBox(self, event):
    self.log.write('EvtCheckBox: %d\n' % event.IsChecked())
    cb = event.GetEventObject()
    if cb.Is3State():
    self.log.write("\t3StateValue: %s\n" % cb.Get3StateValue())


    def OnTestButton(self, evt):
    self.cb1.SetString(1, "FUBAR")

    def OnCloseMe(self, event):
    self.Close(True)

    def OnCloseWindow(self, event):
    self.Destroy()



    app = wx.PySimpleApp()
    frame = wx.Frame(None, -1, "An application launcher")
    Form1(frame, -1)
    frame.Show(1)
    app.MainLoop()





    --




    import wx, sys, os

    ID_ABOUT = 101
    ID_EXIT = 110

    class Frame1(wx.Frame):
    def __init__(self,parent,id,title):
    wx.Frame.__init__(self,parent,wx.ID_ANY, title, size =
    (300, 400), style=wx.DEFAULT_FRAME_STYLE)
    #self.control = wx.TextCtrl(self, 1, style=wx.TE_MULTILINE)
    self.CreateStatusBar() # A Statusbar in the bottom of the
    window
    # Setting up the menu.
    filemenu= wx.Menu()
    filemenu.Append(ID_ABOUT, "&About"," Information about this
    program")
    filemenu.AppendSeparator()
    filemenu.Append(ID_EXIT,"E&xit"," Terminate the program")
    # Creating the menubar.
    menuBar = wx.MenuBar()
    menuBar.Append(filemenu,"&File") # Adding the "filemenu" to
    the MenuBar
    self.SetMenuBar(menuBar) # Adding the MenuBar to the Frame
    content.

    pos = 20
    btn0 = wx.Button(self, -1, "Button Text", (pos, 220))
    self.Bind(wx.EVT_BUTTON, self.OnCloseMe, btn0)
    self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)


    # def OnTestButton(self, evt):
    #Run some code that checks which boxes are ticked
    #Then perform a function for each ticked box

    def OnCloseMe(self, event):
    self.Close(True)

    def OnCloseWindow(self, event):
    self.Destroy()

    self.Show(True)


    class Form1(wx.Panel):
    def __init__(self, parent, id):
    wx.Panel.__init__(self, parent, id)
    self.quote = wx.StaticText(self, -1, "Choose Applications
    :",wx.Point(20,30))

    st = wx.StaticText(self, -1, "Select the application(s) you
    need to open:")#, (10, 10)

    cb1 = wx.CheckBox(self, -1, "Email, Calender")#,(65,40), (150,
    20), wx.NO_BORDER)
    cb2 = wx.CheckBox(self, -1, "Browser")

    self.Bind(wx.EVT_CHECKBOX, self.EvtCheckBox, cb1)
    self.Bind(wx.EVT_CHECKBOX, self.EvtCheckBox, cb2)
    sizer = wx.BoxSizer(wx.VERTICAL)
    sizer.AddMany( [ cb1,
    cb2,
    ])

    border = wx.BoxSizer(wx.VERTICAL)
    border.Add(st, 0, wx.ALL, 15)
    border.Add(sizer, 0, wx.LEFT, 50)
    self.SetSizer(border)


    def EvtCheckBox(self, event):
    self.log.write('EvtCheckBox: %d\n' % event.IsChecked())
    cb = event.GetEventObject()
    if cb.Is3State():
    self.log.write("\t3StateValue: %s\n" % cb.Get3StateValue())


    app = wx.PySimpleApp()
    frame = Frame1(None, -1, "Nuffy's wxPython explorer")
    Form1(frame, -1)
    frame.Show(1)
    app.MainLoop()
     
    , Apr 7, 2006
    #1
    1. Advertising

  2. Guest

    I am also a newbie and learning like you are. I was wondering if do you
    know any wxPython forum just for GUIs ?
    Good luck with your project and hope that some guru helps us out.
     
    , Apr 7, 2006
    #2
    1. Advertising

  3. Guest

    Instead of self.Close(), try parent.Close()

    The self.Close() is closing self, which is a panel. The panel's parent
    is the frame. This will let you keep the button on the frame, which
    eliminates the spacing problem.

    I'm not gonna test it, cuz the darn lines wrap and make it difficult to
    copy your code, but it should go :)


    wrote:
    > I am running through the wxPython guide and docs and extrapolating
    > enough to get confused.
    >
    > BAsed on the tute in the getting started wiki I created a panel that
    > has most of the elements I want; some check boxes and a couple of
    > buttons. The button I have is a simple thing that is supposed to just
    > close (destroy) the app. Only thing is, it destroys the panel and
    > leaves the app behind. I have attempted to place this on teh frame by
    > defining a frame; the button works great and closes the app, but
    > because it isn't part of the panel, the panel is all squished up into
    > the very top left corner and all you can see is the first checkbox,
    > which you can't even check. Can I make a button on the panel destroy
    > the frame?
    >
    > The next question I have is about adding a second button to the panel
    > (or frame, I guess) that will then execute a bunch of things depending
    > on which checkboxes are ticked. My attempts to add the button have
    > been wrong so far, as you'll see with my code.
    >
    > The first code block is my panel only app. The second is how it looks
    > after I defined the Frame first and then moved the Cancel button.
    >
    > TIA
    >
    > Nuffnough
    >
    >
    >
    > --
    >
    > import wx, sys, os
    > class Form1(wx.Panel):
    > def __init__(self, parent, id):
    > wx.Panel.__init__(self, parent, id)
    > self.quote = wx.StaticText(self, -1, "Launching
    > :",wx.Point(20,30))
    >
    > st = wx.StaticText(self, -1, "Select the applications you need
    > to launch:")#, (10, 10)
    >
    > cb1 = wx.CheckBox(self, -1, "Read Calander, Check
    > Email")#,(65,40), (150, 20), wx.NO_BORDER)
    > cb2 = wx.CheckBox(self, -1, "Internet Browser")
    >
    > self.Bind(wx.EVT_CHECKBOX, self.EvtCheckBox, cb1)
    > self.Bind(wx.EVT_CHECKBOX, self.EvtCheckBox, cb2)
    > sizer = wx.BoxSizer(wx.VERTICAL)
    > sizer.AddMany( [ cb1,
    > cb2,
    > ])
    >
    > border = wx.BoxSizer(wx.VERTICAL)
    > border.Add(st, 0, wx.ALL, 15)
    > border.Add(sizer, 0, wx.LEFT, 50)
    > self.SetSizer(border)
    >
    > pos = cb2.GetPosition().x + cb2.GetSize().width + 25
    > btn0 = wx.Button(self, -1, "Cancel", (pos, 150))
    > self.Bind(wx.EVT_BUTTON, self.OnCloseMe, btn0)
    > self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
    >
    > ''' Commented out btn1 cause I couldn't make it work
    > btn1 = wx.Button(self, -1, "Open Apps", (pos + 60, 150))
    > self.Bind(wx.EVT_BUTTON, self.OnTestButton, btn1)
    > '''
    >
    > def EvtCheckBox(self, event):
    > self.log.write('EvtCheckBox: %d\n' % event.IsChecked())
    > cb = event.GetEventObject()
    > if cb.Is3State():
    > self.log.write("\t3StateValue: %s\n" % cb.Get3StateValue())
    >
    >
    > def OnTestButton(self, evt):
    > self.cb1.SetString(1, "FUBAR")
    >
    > def OnCloseMe(self, event):
    > self.Close(True)
    >
    > def OnCloseWindow(self, event):
    > self.Destroy()
    >
    >
    >
    > app = wx.PySimpleApp()
    > frame = wx.Frame(None, -1, "An application launcher")
    > Form1(frame, -1)
    > frame.Show(1)
    > app.MainLoop()
    >
    >
    >
    >
    >
    > --
    >
    >
    >
    >
    > import wx, sys, os
    >
    > ID_ABOUT = 101
    > ID_EXIT = 110
    >
    > class Frame1(wx.Frame):
    > def __init__(self,parent,id,title):
    > wx.Frame.__init__(self,parent,wx.ID_ANY, title, size =
    > (300, 400), style=wx.DEFAULT_FRAME_STYLE)
    > #self.control = wx.TextCtrl(self, 1, style=wx.TE_MULTILINE)
    > self.CreateStatusBar() # A Statusbar in the bottom of the
    > window
    > # Setting up the menu.
    > filemenu= wx.Menu()
    > filemenu.Append(ID_ABOUT, "&About"," Information about this
    > program")
    > filemenu.AppendSeparator()
    > filemenu.Append(ID_EXIT,"E&xit"," Terminate the program")
    > # Creating the menubar.
    > menuBar = wx.MenuBar()
    > menuBar.Append(filemenu,"&File") # Adding the "filemenu" to
    > the MenuBar
    > self.SetMenuBar(menuBar) # Adding the MenuBar to the Frame
    > content.
    >
    > pos = 20
    > btn0 = wx.Button(self, -1, "Button Text", (pos, 220))
    > self.Bind(wx.EVT_BUTTON, self.OnCloseMe, btn0)
    > self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
    >
    >
    > # def OnTestButton(self, evt):
    > #Run some code that checks which boxes are ticked
    > #Then perform a function for each ticked box
    >
    > def OnCloseMe(self, event):
    > self.Close(True)
    >
    > def OnCloseWindow(self, event):
    > self.Destroy()
    >
    > self.Show(True)
    >
    >
    > class Form1(wx.Panel):
    > def __init__(self, parent, id):
    > wx.Panel.__init__(self, parent, id)
    > self.quote = wx.StaticText(self, -1, "Choose Applications
    > :",wx.Point(20,30))
    >
    > st = wx.StaticText(self, -1, "Select the application(s) you
    > need to open:")#, (10, 10)
    >
    > cb1 = wx.CheckBox(self, -1, "Email, Calender")#,(65,40), (150,
    > 20), wx.NO_BORDER)
    > cb2 = wx.CheckBox(self, -1, "Browser")
    >
    > self.Bind(wx.EVT_CHECKBOX, self.EvtCheckBox, cb1)
    > self.Bind(wx.EVT_CHECKBOX, self.EvtCheckBox, cb2)
    > sizer = wx.BoxSizer(wx.VERTICAL)
    > sizer.AddMany( [ cb1,
    > cb2,
    > ])
    >
    > border = wx.BoxSizer(wx.VERTICAL)
    > border.Add(st, 0, wx.ALL, 15)
    > border.Add(sizer, 0, wx.LEFT, 50)
    > self.SetSizer(border)
    >
    >
    > def EvtCheckBox(self, event):
    > self.log.write('EvtCheckBox: %d\n' % event.IsChecked())
    > cb = event.GetEventObject()
    > if cb.Is3State():
    > self.log.write("\t3StateValue: %s\n" % cb.Get3StateValue())
    >
    >
    > app = wx.PySimpleApp()
    > frame = Frame1(None, -1, "Nuffy's wxPython explorer")
    > Form1(frame, -1)
    > frame.Show(1)
    > app.MainLoop()
     
    , Apr 7, 2006
    #3
  4. chris Guest

    Oh, by the way... in your frame's constructor (the Frame1.__init__),
    you'll have to make "parent" a member variable of the class so that
    OnCloseMe has access to it.

    I.e., in the __init__ add
    self.FrameParent = parent

    Then in OnCloseMe do:
    self.FrameParent.Close()
     
    chris, Apr 7, 2006
    #4
  5. John Ladasky Guest

    wrote:
    > I am also a newbie and learning like you are. I was wondering if do you
    > know any wxPython forum just for GUIs ?
    > Good luck with your project and hope that some guru helps us out.


    If you are reading this via Usenet, you can subscribe to the newsgroup
    comp.soft-sys.wxwindows. You will find people there who use the
    wxWidgets port in many different forms, including wxPython.

    You can also visit wxpython.org and subscribe to the mailing list. The
    mailing list is mirrored to the Usenet group. Good luck!

    +-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+
    | Ladasky Home Solar, Inc.: blowing sunshine up your |
    | power grid since March 24, 2005. Fiat lux! |
    +-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+
    | Uptime Downtime kWh generated kWh consumed |
    | 374 days none 6608 7143 |
    +-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+
     
    John Ladasky, Apr 8, 2006
    #5
  6. John Ladasky wrote:

    >
    > wrote:
    >> I am also a newbie and learning like you are. I was wondering if do you
    >> know any wxPython forum just for GUIs ?
    >> Good luck with your project and hope that some guru helps us out.

    >
    > If you are reading this via Usenet, you can subscribe to the newsgroup
    > comp.soft-sys.wxwindows. You will find people there who use the
    > wxWidgets port in many different forms, including wxPython.
    >
    > You can also visit wxpython.org and subscribe to the mailing list. The
    > mailing list is mirrored to the Usenet group. Good luck!
    >
    > +-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+
    > | Ladasky Home Solar, Inc.: blowing sunshine up your |
    > | power grid since March 24, 2005. Fiat lux! |
    > +-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+
    > | Uptime Downtime kWh generated kWh consumed |
    > | 374 days none 6608 7143 |
    > +-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+



    The is alao a book on wxPython at Amazon and others.
    wxPython in action.
     
    Butternut squash, Apr 12, 2006
    #6
  7. Guest

    And why don´t you use Pythoncard, it takes the headache out of messing
    with wxPyhthon
     
    , Apr 12, 2006
    #7
  8. Guest

    wrote:
    > I am running through the wxPython guide and docs and extrapolating
    > enough to get confused.


    There is mailing list for wxPython users -
    . It is pretty active and its
    members, including Robin Dunn the main wxPython developer, are always
    very helpful.

    If you post code there, I suggest you include it as an attachment to
    avoid line wrapping in the message body - the one thing Python doesn't
    like!

    Regards,
    David Hughes
     
    , Apr 12, 2006
    #8
    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. Anand
    Replies:
    1
    Views:
    374
    Cliff Wells
    Jul 23, 2003
  2. ulysses
    Replies:
    4
    Views:
    823
    Werner Schiendl
    Oct 22, 2003
  3. Logan
    Replies:
    5
    Views:
    795
    David Bolen
    Dec 11, 2003
  4. Ruben Charles
    Replies:
    6
    Views:
    519
    =?ISO-8859-1?Q?Michael_Str=F6der?=
    Oct 25, 2005
  5. Robin Dunn
    Replies:
    0
    Views:
    548
    Robin Dunn
    Mar 28, 2006
Loading...

Share This Page