根据要求演示 Grid sizer。
我选择了一个GridBagSizer
,它似乎最适合您的要求。
import wx
data = [
["99550","539761","016833-0695","Shipped","03/27/20","Unknown"],
["99551","539761","xxxxxx-xxxx","Shipped","03/22/20","Unknown"],
["99554","539761","016833-0695","Warehouse 1","01/12/19","Unknown"],
['Invalid RMA number','','','','','',''],
["99555","539761","777777-0695","Warehouse 2","02/27/20","Unknown"],
["99556","539761","016833-XXXX","Shipped","03/27/20","03/24/20"],
['Invalid RMA number','','','','','','']
]
class Example(wx.Frame):
def __init__(self, parent, title):
super(Example, self).__init__(parent, title = title)
self.InitUI()
self.Centre()
self.Show()
def InitUI(self):
self.idx = 0
panel = wx.Panel(self)
sizer = wx.GridBagSizer(0,0)
self.rma = wx.TextCtrl(panel,style=wx.TE_PROCESS_ENTER)
sizer.Add(self.rma, pos = (0, 1), flag = wx.ALIGN_CENTRE_VERTICAL)
EnterB = wx.Button(panel, label = "Enter RMA")
sizer.Add(EnterB, pos = (0,2),flag = wx.ALL, border = 5)
text = wx.StaticText(panel, label = "RMA :")
sizer.Add(text, pos = (1, 0), flag = wx.ALIGN_CENTRE_VERTICAL|wx.ALL, border = 5)
self.tc = wx.TextCtrl(panel, style=wx.TE_READONLY, size=(150,-1))
sizer.Add(self.tc, pos = (1, 1), flag = wx.EXPAND)
text1 = wx.StaticText(panel, label = "DMR :")
sizer.Add(text1, pos = (2, 0), flag = wx.ALIGN_CENTRE_VERTICAL|wx.ALL, border = 5)
self.tc1 = wx.TextCtrl(panel, style=wx.TE_READONLY)
sizer.Add(self.tc1, pos = (2,1), flag = wx.EXPAND)
text2 = wx.StaticText(panel,label = "Serial :")
sizer.Add(text2, pos = (3, 0), flag = wx.ALIGN_CENTRE_VERTICAL|wx.ALL, border = 5)
self.tc2 = wx.TextCtrl(panel, style=wx.TE_READONLY)
sizer.Add(self.tc2, pos = (3,1), flag = wx.EXPAND)
text3 = wx.StaticText(panel,label = "Status :")
sizer.Add(text3, pos = (4, 0), flag = wx.ALIGN_CENTRE_VERTICAL|wx.ALL, border = 5)
self.tc3 = wx.TextCtrl(panel, style=wx.TE_READONLY)
sizer.Add(self.tc3, pos = (4,1),flag = wx.EXPAND)
text4 = wx.StaticText(panel,label = "Created:")
sizer.Add(text4, pos = (5, 0), flag = wx.ALIGN_CENTRE_VERTICAL|wx.ALL, border = 5)
self.tc4 = wx.TextCtrl(panel, style=wx.TE_READONLY)
sizer.Add(self.tc4, pos = (5,1), flag = wx.EXPAND)
text5 = wx.StaticText(panel,label = "Update :")
sizer.Add(text5, pos = (6, 0), flag = wx.ALIGN_CENTRE_VERTICAL)
self.tc5 = wx.TextCtrl(panel, style=wx.TE_READONLY)
sizer.Add(self.tc5, pos = (6,1), flag = wx.EXPAND)
Next = wx.Button(panel, label = "Demo")
sizer.Add(Next, pos = (7, 1))
panel.SetSizerAndFit(sizer)
EnterB.Bind(wx.EVT_BUTTON, self.OnRma)
self.rma.Bind(wx.EVT_TEXT_ENTER, self.OnRma)
Next.Bind(wx.EVT_BUTTON, self.OnNext)
def OnRma(self, event):
rma = self.rma.GetValue()
idx = [i for i, e in enumerate(data) if e[0] == rma]
if idx:
self.idx = idx[0]
self.OnNext(None)
else:
self.tc.SetValue('Invalid RMA number')
self.tc1.SetValue('')
self.tc2.SetValue('')
self.tc3.SetValue('')
self.tc4.SetValue('')
self.tc5.SetValue('')
def OnNext(self, event):
self.rma.SetValue('')
self.tc.SetValue(data[self.idx][0])
self.tc1.SetValue(data[self.idx][1])
self.tc2.SetValue(data[self.idx][2])
self.tc3.SetValue(data[self.idx][3])
self.tc4.SetValue(data[self.idx][4])
self.tc5.SetValue(data[self.idx][5])
self.idx += 1
if self.idx > len(data) - 1:
self.idx = 0
app = wx.App()
Example(None, title = 'GridBag Demo')
app.MainLoop()
用途:
- 输入 RMA 编号(99550、99551、99554、99555 或 99556)并按 Enter 或
Enter Rma
按钮
- 输入一些无效的 RMA 并按 Enter 或
Enter Rma
按钮
- 单击
Demo
按钮,它将滚动浏览数据