]>
Commit | Line | Data |
---|---|---|
be05b434 RD |
1 | """ |
2 | XRC is an XML-based resource format for wxPython. With it you can | |
3 | define the layout of widgets, and then load that XRC at runtime to | |
4 | create the layout. There are several GUI designers available that | |
5 | understand the XRC format, a simple one called XRCed comes with | |
6 | wxPython. | |
7 | """ | |
8 | ||
9 | import wx | |
10 | import wx.xrc | |
11 | ||
12 | ||
13 | class MyFrame(wx.Frame): | |
14 | def __init__(self): | |
15 | wx.Frame.__init__(self, None, title="XRC Sample", | |
16 | size=(400,225)) | |
17 | res = wx.xrc.XmlResource("xrcsample.xrc") | |
18 | panel = res.LoadPanel(self, "ID_PANEL") | |
19 | ||
20 | self.Bind(wx.EVT_BUTTON, self.OnOk, | |
21 | wx.xrc.XRCCTRL(self, "ID_OK")) | |
22 | self.Bind(wx.EVT_BUTTON, self.OnCancel, | |
23 | wx.xrc.XRCCTRL(self, "ID_CANCEL")) | |
24 | ||
25 | ||
26 | def OnOk(self, evt): | |
27 | namectrl = wx.xrc.XRCCTRL(self, "ID_NAME") | |
28 | name = namectrl.GetValue() | |
29 | emailctrl = wx.xrc.XRCCTRL(self, "ID_EMAIL") | |
30 | email = emailctrl.GetValue() | |
31 | phonectrl = wx.xrc.XRCCTRL(self, "ID_PHONE") | |
32 | phone = phonectrl.GetValue() | |
33 | print "You entered:\n name: %s\n email: %s\n phone: %s\n" \ | |
34 | % (name, email, phone) | |
35 | ||
36 | def OnCancel(self, evt): | |
37 | self.Close() | |
38 | ||
39 | ||
40 | app = wx.PySimpleApp(redirect=True) | |
41 | frm = MyFrame() | |
42 | frm.Show() | |
43 | app.MainLoop() |