All Pages All Books|
|
||||||||
|
How do I add objects and subwindows to a frame?
|
47
|
|||||||
|
|
||||||||
|
Figure 2.6 uses style=wx.DEFAULT_FRAME_STYLE | wx.FRAME_TOOL_WINDOW.
|
||||||||
|
|
||||||||
![]() |
![]() |
|||||||
|
|
||||||||
|
Figure 2.6 A toolbar frame, with a smaller title bar and no system menu
|
Figure 2.7 A frame with a help button
|
|||||||
|
|
||||||||
|
Figure 2.7 uses the extended style wx.help.frame_ex_contexthelp, which is described in chapter 8.
Now that we’ve seen how to create wx.Frame objects, we’ll start to show how to make them useful, by adding additional widgets inside the frame.
2.6 How do I add objects and subwindows to a frame?
We’ve described how to create wx.Frame objects, but as yet the frames are not very interesting. For one thing, they are empty. In this section, we’ll show you the basics of inserting objects and subwindows inside your frame for the user to interact with.
2.6.1 Adding widgets to a frame
|
||||||||
|
|
||||||||
|
Figure 2.8 shows a custom frame subclass called insertFrame. When the close button is clicked, the window will close and the application will end.
|
![]() |
|||||||
|
Listing 2.3 defines the wx.Frame subclass shown in figure 2.8. Not all of the concepts in this snippet have been covered yet, so don’t worry if some things are not clear.
|
||||||||
|
Figure 2.8 The InsertFrame window is an example demonstrating the basics of inserting items into a frame.
|
||||||||
|
|
||||||||
|
|
Listing 2.3 The InsertFrame code
|
|
||||||
|
|
||||||||
|
#!/usr/bin/env python
import wx
class InsertFrame(wx.Frame):
|
Adding the button to the panel
|
0
|
||||||
|
|
||||||||
|
def __init__(self, parent, id):
wx.Frame.__init__(self, parent, id, 'Frame With Button',
size=(300, 100)) panel = wx.Panel(self) b Creating the panel button = wx.Button(panel, label="Close", pos=(125, 10),
|
<M
|
|||||||
|
|
||||||||
All Pages All Books