我有一组TextCtrl,我需要时编辑它。
import wx
class MyCheckBox(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, 'Values', size=(490, 450))
panel = wx.Panel(self, -1)
List = [(70, 55), (170, 55), (270, 55), (370, 55),
(70, 85), (170, 85), (270, 85), (370, 85)]
val = []
for i in range(0,8):
value = -999
val.append(value)
for p,v in zip(List,val):
self.value = wx.TextCtrl(panel, -1, value=str(v), pos=p, size=(60,25))
self.btnOK = wx.Button(panel, label="OK", pos=(190, 355))
self.Bind(wx.EVT_BUTTON, self.OnOK, id = self.btnOK.GetId())
def OnOK(self, event):
self.Show(False)
目前,所有这些的默认值都是'-999'。当我按OK时,如何在进程结束时将它们检索到列表?
答案 0 :(得分:1)
您需要将文本控件保留在列表中,以便之后恢复其值:
import wx
class MyCheckBox(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, 'Values', size=(490, 250))
panel = wx.Panel(self, -1)
positions = [(70, 55), (170, 55), (270, 55), (370, 55),
(70, 85), (170, 85), (270, 85), (370, 85)]
values = ['a', 'a','a', 'a','a', 'a','a', 'a',]
self.controls = []
for pos, value in zip(positions, values):
control = wx.TextCtrl(panel, -1, value=str(value),
pos=pos, size=(60,25))
self.controls.append(control)
self.to_show = wx.TextCtrl(panel, -1, value='',
pos=(90, 120), size=(290,25))
self.btnOK = wx.Button(panel, label="OK", pos=(190, 180))
self.Bind(wx.EVT_BUTTON, self.OnOK, self.btnOK)
def OnOK(self, event):
all_values = []
for control in self.controls:
all_values.append(control.GetValue())
self.to_show.SetValue(str(all_values))
if __name__ == '__main__':
app = wx.PySimpleApp()
f = MyCheckBox()
f.Show()
app.MainLoop()