Yes, I do know that this questions gets asked a lot, and yes I did
search Gmane before posting this :). Now, on with the question...
I want one Frame with custom image as a background, and I want to
place some widgets (few Buttons and few ListCtrls) on top of it.
Searching the list I found out one way to apply background image, and
that is to use OnPaint() function and within it to use dc.DrawBitmap()
to actually draw the background. This works for me, but I'm wondering
is this the proper way to do it?
Now, the troubles begin when I add widgets to the frame, namely a
button. I manually set it's size and position, but instead of that it
gets stretched and fills the entire frame (and of course, blocking the
background image). If I move the button code from Frame's __init__()
function, and place it inside OnPaint(), it somehow works, and the
button is where it should be. I'm not sure if this is the right way to
add widgets? It somehow seems stupid to create them every time
EVT_PAINT gets generated... so, how do I properly add widgets to my
frame?
I have many more custom graphics related questions coming up, but I'll
wait until I figure this one out :). But, if anyone has a pointer to
some documentation, or maybe an example of a wxPython app with some
custom graphics, it would be more than helpfull...
Thanks guys...
···
--
Karlo Lozovina -- Mosor
"Parce mihi domine quia Dalmata sum."
I've struggled with the same thing for a while and came to the unfortunate conclusion that mixing background images with controls requires quite a lot of manual work. I was trying to build a skinnable interface. I got that working to a certain extent.
Maybe the attached code will help you along. I've implemented a panel that you can set a background to and a button that is based on 4 bitmaps (normal, hot, pressed and disabled).
Yes, I do know that this questions gets asked a lot, and yes I did
search Gmane before posting this :). Now, on with the question...
I want one Frame with custom image as a background, and I want to
place some widgets (few Buttons and few ListCtrls) on top of it.
Searching the list I found out one way to apply background image, and
that is to use OnPaint() function and within it to use dc.DrawBitmap()
to actually draw the background. This works for me, but I'm wondering
is this the proper way to do it?
Now, the troubles begin when I add widgets to the frame, namely a
button. I manually set it's size and position, but instead of that it
gets stretched and fills the entire frame (and of course, blocking the
background image). If I move the button code from Frame's __init__()
function, and place it inside OnPaint(), it somehow works, and the
button is where it should be. I'm not sure if this is the right way to
add widgets? It somehow seems stupid to create them every time
EVT_PAINT gets generated... so, how do I properly add widgets to my
frame?
I have many more custom graphics related questions coming up, but I'll
wait until I figure this one out :). But, if anyone has a pointer to
some documentation, or maybe an example of a wxPython app with some
custom graphics, it would be more than helpfull...
Yes, I do know that this questions gets asked a lot, and yes I did
search Gmane before posting this :). Now, on with the question...
I want one Frame with custom image as a background, and I want to
place some widgets (few Buttons and few ListCtrls) on top of it.
Searching the list I found out one way to apply background image, and
that is to use OnPaint() function and within it to use dc.DrawBitmap()
to actually draw the background. This works for me, but I'm wondering
is this the proper way to do it?
Depending on platform using EVT_ERASE_BACKGROUND might be a bit better. See the demo for a few examples.
Now, the troubles begin when I add widgets to the frame, namely a
button. I manually set it's size and position, but instead of that it
gets stretched and fills the entire frame (and of course, blocking the
background image). If I move the button code from Frame's __init__()
function, and place it inside OnPaint(), it somehow works, and the
button is where it should be. I'm not sure if this is the right way to
add widgets? It somehow seems stupid to create them every time
EVT_PAINT gets generated... so, how do I properly add widgets to my
frame?
wx.Frame has a feature that if it has only one child widget that it resizes it to fill the client area of the frame. You can work around this by overriding the default sizing behavior of the frame, either by using a sizer for managing the layout, or by implementing your own EVT_SIZE handler and positioning the child there. On the other hand, the more proper way to do this is to put your button (and custom background) on a wx.Panel and then putting the panel in the frame and letting the frame resize the panel to fill the frame.
···
--
Robin Dunn
Software Craftsman http://wxPython.org Java give you jitters? Relax with wxPython!