Hello everypne.
I am new to wxPython, and I was wondering if anyone can explain me
what is the diffrence between a Frame ojbect and a Panel object?
and when should we use them?
Thank you guys for the help you are providing.
Hello everypne.
I am new to wxPython, and I was wondering if anyone can explain me
what is the diffrence between a Frame ojbect and a Panel object?
and when should we use them?
Thank you guys for the help you are providing.
Hello everypne.
I am new to wxPython, and I was wondering if anyone can explain me
what is the diffrence between a Frame ojbect and a Panel object?
A Frame is what most computer users would think of as a window,
like when one has Word or Firefox open, the whole outer rectangle
is a frame. It typically has a bar on top and close/minimize/restore
buttons and a resize border.
A panel is a rectangular region within a frame.
and when should we use them?
Use a frame when you need a window for your application (which
is always if it is a GUI). Use a panel (within that frame) to place
other widgets onto. Don't place (most) widgets right onto the frame
itself; there are some problems with that. You can and often will
use multiple panels within the same frame.
This will make most sense in working through short examples.
There are lots of tutorials for wxPython out there if you Google
for them, and also see the wxPython wiki, which has a few
different approaches:
http://wiki.wxpython.org/Front Page
Welcome and good luck!
Che
On Wed, Sep 30, 2009 at 2:52 PM, Nikul Padhya <nikul.padhya@gmail.com> wrote:
Sorry, that link should have been:
Hi,
Hello everypne.
I am new to wxPython, and I was wondering if anyone can explain me
what is the diffrence between a Frame ojbect and a Panel object?
A Frame is a top level window and can contain Panels.
A Panel is a container window that can contain (pretty much) any non-top level window (buttons, checkboxes, etct...)
class MyFrame(wx.Frame):
def __init__(self, parent, ...):
wx.Frame.__init__(self, parent)
# Attributes
self.panel = MyPanel(self)
class MyPanel(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent)
# Attributes
self.button = wx.Button(self, label="Hello")
and when should we use them?
A Frame or Dialog is your Top level container, a Panel is the the next level of containment within your Frame or Dialog.
Cody
On Sep 30, 2009, at 1:52 PM, Nikul Padhya wrote:
..and also,
a Frame can be used as Parent (can exist without anything else) while
Panel cannot and Is not a parent!
That's not completely correct as a panel can be the parent of its
children (i.e. any non-top level widgets like buttons, checkboxes,
etc).
On Sep 30, 6:42 pm, evstevemd <mwinjili...@gmail.com> wrote:
..and also,
a Frame can be used as Parent (can exist without anything else) while
Panel cannot and Is not a parent!
-------------------
Mike Driscoll
Hi,
On Thu, Oct 1, 2009 at 9:04 AM, Mike Driscoll <kyosohma@gmail.com> wrote:
On Sep 30, 6:42 pm, evstevemd <mwinjili...@gmail.com> wrote:
..and also,
a Frame can be used as Parent (can exist without anything else) while
Panel cannot and Is not a parent!That's not completely correct as a panel can be the parent of its
children (i.e. any non-top level widgets like buttons, checkboxes,
etc).
Actually to be really precise, A panel can in fact be the _parent_ of
any other window, top level windows included, it cannot however be a
_container_ for a top level window
Cody
Aha...that makes my head hurt. I must have a muddled understanding of
parents then as I thought the parent typically contained the child.
Maybe you could elucidate on that a bit?
- Mike
On Oct 1, 9:20 am, Cody Precord <codyprec...@gmail.com> wrote:
Hi,
On Thu, Oct 1, 2009 at 9:04 AM, Mike Driscoll <kyoso...@gmail.com> wrote:
> On Sep 30, 6:42 pm, evstevemd <mwinjili...@gmail.com> wrote:
>> ..and also,
>> a Frame can be used as Parent (can exist without anything else) while
>> Panel cannot and Is not a parent!> That's not completely correct as a panel can be the parent of its
> children (i.e. any non-top level widgets like buttons, checkboxes,
> etc).Actually to be really precise, A panel can in fact be the _parent_ of
any other window, top level windows included, it cannot however be a
_container_ for a top level windowCody
Hi,
Hi,
>> ..and also,
>> a Frame can be used as Parent (can exist without anything else) while
>> Panel cannot and Is not a parent!> That's not completely correct as a panel can be the parent of its
> children (i.e. any non-top level widgets like buttons, checkboxes,
> etc).Actually to be really precise, A panel can in fact be the _parent_ of
any other window, top level windows included, it cannot however be a
_container_ for a top level windowCody
Aha...that makes my head hurt. I must have a muddled understanding of
parents then as I thought the parent typically contained the child.
Maybe you could elucidate on that a bit?
Well there are really two hierarchies that we are talking about here.
1) the Window parental hierarchy
2) the layout containment hierarchy
The simple example below shows both:
1) the MyFrame is the parent and container of MyPanel
2) the MyPanel is the parent of a Frame and a Button but only contains
the Button
import wx
class MyFrame(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent, title="test")
self.panel = MyPanel(self)
class MyPanel(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent)
self.child_frame = wx.Frame(self, title="child of panel")
self.child_frame.Show()
self.button = wx.Button(self, label="child contained by panel")
self.SetBackgroundColour(wx.BLACK)
if __name__ == '__main__':
app = wx.App(False)
frame = MyFrame(None)
frame.Show()
app.MainLoop()
Cody
On Thu, Oct 1, 2009 at 9:39 AM, Mike Driscoll <kyosohma@gmail.com> wrote:
On Oct 1, 9:20 am, Cody Precord <codyprec...@gmail.com> wrote:
On Thu, Oct 1, 2009 at 9:04 AM, Mike Driscoll <kyoso...@gmail.com> wrote:
> On Sep 30, 6:42 pm, evstevemd <mwinjili...@gmail.com> wrote:
Cody,
On Oct 1, 9:50 am, Cody Precord <codyprec...@gmail.com> wrote:
Hi,
On Thu, Oct 1, 2009 at 9:39 AM, Mike Driscoll <kyoso...@gmail.com> wrote:
> On Oct 1, 9:20 am, Cody Precord <codyprec...@gmail.com> wrote:
>> Hi,>> On Thu, Oct 1, 2009 at 9:04 AM, Mike Driscoll <kyoso...@gmail.com> wrote:
>> > On Sep 30, 6:42 pm, evstevemd <mwinjili...@gmail.com> wrote:
>> >> ..and also,
>> >> a Frame can be used as Parent (can exist without anything else) while
>> >> Panel cannot and Is not a parent!>> > That's not completely correct as a panel can be the parent of its
>> > children (i.e. any non-top level widgets like buttons, checkboxes,
>> > etc).>> Actually to be really precise, A panel can in fact be the _parent_ of
>> any other window, top level windows included, it cannot however be a
>> _container_ for a top level window>> Cody
> Aha...that makes my head hurt. I must have a muddled understanding of
> parents then as I thought the parent typically contained the child.
> Maybe you could elucidate on that a bit?Well there are really two hierarchies that we are talking about here.
1) the Window parental hierarchy
2) the layout containment hierarchyThe simple example below shows both:
1) the MyFrame is the parent and container of MyPanel
2) the MyPanel is the parent of a Frame and a Button but only contains
the Buttonimport wx
class MyFrame(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent, title="test")self\.panel = MyPanel\(self\)
class MyPanel(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent)self\.child\_frame = wx\.Frame\(self, title="child of panel"\) self\.child\_frame\.Show\(\) self\.button = wx\.Button\(self, label="child contained by panel"\) self\.SetBackgroundColour\(wx\.BLACK\)
if __name__ == '__main__':
app = wx.App(False)
frame = MyFrame(None)
frame.Show()
app.MainLoop()Cody
That's a good illustration. But why would you ever do that? Thanks,
though.
Mike
Hi,
That's a good illustration. But why would you ever do that? Thanks,
though.
Whether you want to do it or not is another question, I was just
illustrating the possibilities
But there are a number of cases I think think of that are reasonable
to do this, here are a few common ones. (of course in the top two you
could also do self.GetTopLevelParent() to use as the parent for the
popup, but 'self' is much less to type )
1) If you want to show a modal dialog from a handler and only want it
to be modal to the given window as opposed to the entire application.
2) You have a non modal frame/dialog that you wish to be automatically
dismissed/destroyed when when its parent window is destroyed.
3) You have an event that happens in the Frame/Dialog that you wish to
have propagated back to an event handler in the parent panel.
Cody
On Thu, Oct 1, 2009 at 10:38 AM, Mike Driscoll <kyosohma@gmail.com> wrote:
These are some cool tricks. Thanks for sharing. I'll have to try to
figure out a way to remember them.
- Mike
On Oct 1, 11:21 am, Cody Precord <codyprec...@gmail.com> wrote:
Hi,
On Thu, Oct 1, 2009 at 10:38 AM, Mike Driscoll <kyoso...@gmail.com> wrote:
> That's a good illustration. But why would you ever do that? Thanks,
> though.Whether you want to do it or not is another question, I was just
illustrating the possibilitiesBut there are a number of cases I think think of that are reasonable
to do this, here are a few common ones. (of course in the top two you
could also do self.GetTopLevelParent() to use as the parent for the
popup, but 'self' is much less to type)
1) If you want to show a modal dialog from a handler and only want it
to be modal to the given window as opposed to the entire application.2) You have a non modal frame/dialog that you wish to be automatically
dismissed/destroyed when when its parent window is destroyed.3) You have an event that happens in the Frame/Dialog that you wish to
have propagated back to an event handler in the parent panel.Cody
Cody Precord wrote:
1) If you want to show a modal dialog from a handler and only want it
to be modal to the given window as opposed to the entire application.
ooo -- I like that! I never knew that was possible.
2) You have a non modal frame/dialog that you wish to be automatically
dismissed/destroyed when when its parent window is destroyed.
though it this case, it's likely that parent would be a frame/dialog..
Could you make a Wiki page of all this? It's great stuff to teach folks.
-Chris
--
Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker@noaa.gov
Hi,
Cody Precord wrote:
1) If you want to show a modal dialog from a handler and only want it
to be modal to the given window as opposed to the entire application.ooo -- I like that! I never knew that was possible.
I don't think this works on all/any platforms with wx2.8 (not on
windows at least), will have to double check others later as my memory
is not so good at the moment (been working too much and with too many
different frameworks lately so things are starting to get a little
mixed up upstairs ).
Though IIRC there are changes in 2.9 to support non-application modal
dialogs (and in particular Sheet dialogs on OSX).
2) You have a non modal frame/dialog that you wish to be automatically
dismissed/destroyed when when its parent window is destroyed.though it this case, it's likely that parent would be a frame/dialog..
Could you make a Wiki page of all this? It's great stuff to teach folks.
Once upon a time I seem to remember seeing a page on the wiki that had
diagrams and stuff explaining the containment hierarchy and stuff
already. Was going to check but cant seem to get to the wiki to see at
the moment.
Cody
On Thu, Oct 1, 2009 at 1:37 PM, Christopher Barker <Chris.Barker@noaa.gov> wrote:
duh! I didn't knew it!
Thanks Cody!
On Oct 1, 9:57 pm, Cody Precord <codyprec...@gmail.com> wrote:
Hi,
On Thu, Oct 1, 2009 at 1:37 PM, Christopher Barker > > <Chris.Bar...@noaa.gov> wrote:
> Cody Precord wrote:
>> 1) If you want to show a modal dialog from a handler and only want it
>> to be modal to the given window as opposed to the entire application.> ooo -- I like that! I never knew that was possible.
I don't think this works on all/any platforms with wx2.8 (not on
windows at least), will have to double check others later as my memory
is not so good at the moment (been working too much and with too many
different frameworks lately so things are starting to get a little
mixed up upstairs).
Though IIRC there are changes in 2.9 to support non-application modal
dialogs (and in particular Sheet dialogs on OSX).>> 2) You have a non modal frame/dialog that you wish to be automatically
>> dismissed/destroyed when when its parent window is destroyed.> though it this case, it's likely that parent would be a frame/dialog..
> Could you make a Wiki page of all this? It's great stuff to teach folks.
Once upon a time I seem to remember seeing a page on the wiki that had
diagrams and stuff explaining the containment hierarchy and stuff
already. Was going to check but cant seem to get to the wiki to see at
the moment.Cody