它有点乱,但我没有时间把它清理干净的那一刻,就应该在showconnstring类使用分级机。
import wx
class MyFrame(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent, -1, "Dialog Test",size=(500,400))
self.panel = wx.Panel(self)
sizer = wx.BoxSizer(wx.VERTICAL)
self.log = wx.TextCtrl(self.panel, wx.ID_ANY, size=(400,300),style = wx.TE_MULTILINE|wx.TE_READONLY|wx.VSCROLL)
self.button = wx.Button(self.panel, label="Click me")
sizer.Add(self.log, 0, wx.EXPAND | wx.ALL, 10)
sizer.Add(self.button, 0, wx.EXPAND | wx.ALL, 10)
self.panel.SetSizer(sizer)
self.Bind(wx.EVT_BUTTON, self.OnButton)
def OnButton(self,event):
dlg = ShowConnString(parent = self.panel)
dlg.ShowModal()
if dlg.result_name:
self.log.AppendText("Name: "+dlg.result_name+"\n")
self.log.AppendText("Spin: "+str(dlg.result_spin)+"\n")
self.log.AppendText("Choice: "+str(dlg.result_choice)+"\n")
else:
self.log.AppendText("No selection made\n")
dlg.Destroy()
class ShowConnString(wx.Dialog):
def __init__(self, parent):
wx.Dialog.__init__(self, parent, wx.ID_ANY, "Save", size= (650,220))
self.panel = wx.Panel(self,wx.ID_ANY)
self.lblname = wx.StaticText(self.panel, label="Connection", pos=(20,20))
self.editname = wx.TextCtrl(self.panel, value="server=127.0.0.1", pos=(110,20), size=(500,-1))
self.lbl_1 = wx.StaticText(self.panel, wx.ID_ANY, ("Spin Control"), pos=(20,60))
self.spin = wx.SpinCtrl(self.panel, wx.ID_ANY, "", min=1, max=10, pos=(110,60))
self.lbl_2 = wx.StaticText(self.panel, wx.ID_ANY, ("Choice"),pos=(20,100))
self.choice = wx.Choice(self.panel, wx.ID_ANY, choices=[("Choice 1"), ("Choice 2"), ("Choice 3")], pos=(110,100))
self.saveButton =wx.Button(self.panel, label="Save", pos=(110,160))
self.closeButton =wx.Button(self.panel, label="Cancel", pos=(210,160))
self.saveButton.Bind(wx.EVT_BUTTON, self.SaveConnString)
self.closeButton.Bind(wx.EVT_BUTTON, self.OnQuit)
self.Bind(wx.EVT_CLOSE, self.OnQuit)
self.spin.SetValue(0)
self.choice.SetSelection(0)
self.Show()
def OnQuit(self, event):
self.result_name = None
self.Destroy()
def SaveConnString(self, event):
self.result_name = self.editname.GetValue()
self.result_spin = self.spin.GetValue()
self.result_choice = self.choice.GetSelection()
self.Destroy()
app = wx.App()
frame = MyFrame(None)
frame.Show()
app.MainLoop()
您是否试过'self.Destroy()' –
是的。 Self.destroy()杀死了盒子的内部,即,按钮,灰色背景和文本框,但框架本身仍显示为深灰色。 – pickarooney