개정판 4135735d
Add wxExample
DTI_PID/DTI_PID/wxExample.py | ||
---|---|---|
1 |
import wx |
|
2 |
import os |
|
3 |
|
|
4 |
class Example(wx.Frame): |
|
5 |
def __init__(self, parent, title): |
|
6 |
super(Example, self).__init__(parent, title=title, size=(260, 180)) |
|
7 |
|
|
8 |
self.InitUI() |
|
9 |
self.Centre() |
|
10 |
self.Show() |
|
11 |
|
|
12 |
def InitUI(self): |
|
13 |
panel = wx.Panel(self) |
|
14 |
|
|
15 |
menubar = wx.MenuBar() |
|
16 |
filem = wx.Menu() |
|
17 |
openm = filem.Append(wx.ID_OPEN, "O&pen\tAlt-O", "Open a file") |
|
18 |
self.Bind(wx.EVT_MENU, self.OnOpen, openm) |
|
19 |
exitm = filem.Append(wx.ID_EXIT, "E&xit\tAlt-X", "Close window and exit program.") |
|
20 |
self.Bind(wx.EVT_MENU, self.OnClose, exitm) |
|
21 |
editm = wx.Menu() |
|
22 |
helpm = wx.Menu() |
|
23 |
|
|
24 |
menubar.Append(filem, '&File') |
|
25 |
menubar.Append(editm, '&Edit') |
|
26 |
menubar.Append(helpm, '&Help') |
|
27 |
self.SetMenuBar(menubar) |
|
28 |
|
|
29 |
hbox = wx.BoxSizer(wx.HORIZONTAL) |
|
30 |
|
|
31 |
flexgridsizer = wx.FlexGridSizer(2, 1, 0, 0) |
|
32 |
|
|
33 |
languages = ['C', 'C++', 'Python', 'Java', 'Perl'] |
|
34 |
self.combo = wx.ComboBox(panel, choices = languages) |
|
35 |
textctrl = wx.TextCtrl(panel, style=wx.TE_MULTILINE) |
|
36 |
flexgridsizer.AddMany([(self.combo, 0, wx.EXPAND), (textctrl, 1, wx.EXPAND)]) |
|
37 |
|
|
38 |
flexgridsizer.AddGrowableRow(1, 0) |
|
39 |
flexgridsizer.AddGrowableCol(0, 0) |
|
40 |
|
|
41 |
hbox.Add(flexgridsizer, proportion=1, flag=wx.ALL|wx.EXPAND, border=5) |
|
42 |
panel.SetSizer(hbox) |
|
43 |
#panel.SetSizer(flexgridsizer) |
|
44 |
|
|
45 |
def OnOpen(self, event): |
|
46 |
wildcard = "Image files (*.png,*.bmp)|*.png;*.bmp||" |
|
47 |
fdlg = wx.FileDialog(None, "Choose a file", os.getcwd(), "", wildcard, wx.FD_OPEN) |
|
48 |
if fdlg.ShowModal() == wx.ID_OK: |
|
49 |
print(fdlg.GetPath()) |
|
50 |
fdlg.Destroy() |
|
51 |
|
|
52 |
def OnClose(self, event): |
|
53 |
dlg = wx.MessageDialog(self, |
|
54 |
"Do you really want to close this program?", |
|
55 |
"Confrim Exit", wx.OK|wx.CANCEL|wx.ICON_QUESTION) |
|
56 |
result = dlg.ShowModal() |
|
57 |
dlg.Destroy() |
|
58 |
|
|
59 |
if result == wx.ID_OK: |
|
60 |
self.Destroy() |
|
61 |
|
|
62 |
|
|
63 |
if __name__ == '__main__': |
|
64 |
app = wx.App() |
|
65 |
Example(None, title='') |
|
66 |
app.MainLoop() |
내보내기 Unified diff