当我从 childframe 类中的 pubsub 订阅消息时遇到问题。我不知道如何编写正确的代码来显示来自大型机的选择。我也无法在 childframe 类中传递定义行。我不知道我是如何指定我的问题的,我知道这很难理解,但在这段代码中,我想你会确切地找到我所要求的。我是 python 新手,所以 plizz 不要批评
import wx
from wx.lib.pubsub import Publisher as pub
import pyodbc
cnxn = pyodbc.connect("DRIVER={SQL Server Native Client 11.0};SERVER=10.75.79.215;DATABASE=HUB_DATA;UID=sa;PWD=password")
cursor = cnxn.cursor()
class Mainframe(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent)
self.panel = wx.Panel(self)
self.quote1 = wx.StaticText(self.panel, label = "id")
self.test=wx.StaticText(self.panel, label = "")
self.editquote1 = wx.TextCtrl(self.panel, size = (140, -1))
self.button = wx.Button(self.panel, label = "search")
#
self.windowSizer = wx.BoxSizer()
self.windowSizer.Add(self.panel, wx.ID_ANY, wx.ALL | wx.EXPAND)
#
self.sizer = wx.GridBagSizer(6, 6)
self.sizer.Add(self.quote1, (0, 0))
self.sizer.Add(self.editquote1, (0, 1))
self.sizer.Add(self.button, (3, 1))
self.sizer.Add(self.test, (4, 1))
#
self.border = wx.BoxSizer()
self.border.Add(self.sizer, 1, wx.ALL | wx.EXPAND, 6)
#
self.panel.SetSizerAndFit(self.border)
self.SetSizerAndFit(self.windowSizer)
#
self.button.Bind(wx.EVT_BUTTON, self.Onbutton and self.afterOnbutton)
def Onbutton(self,e):
var = self.editquote1.GetValue()
if len(var)==9:
self.test.SetLabel('True')
if len(var)==9:
cursor.execute("""SELECT COUNT(DPVLDT) as amount
FROM [HBGE_Reports].[dbo].[hub_DDJPFile] s
where exists (SELECT [ZGDCS]
FROM [HUB_DATA].[dbo].[SSCUSTP] d
where [ZGIDNO]=?
and
s.DPACS=d.ZGDCS)""",str(var))
raw = cursor.fetchone()
a = raw.amount
pub.sendMessage("amount", a)
cursor.execute("""declare @a varchar(20)
set @a=?
SELECT [DPVLDT]
,[DPCPDT]
,[DPACB]
,[DPACS]
,[DPACX]
,[DPCYCD]
,[DPDLCD]
,[RCY_AMOUNT]
,[LCY_AMOUNT]
,[DPBLBL]
,[DPNAR1]
,[DPNAR2]
,[DPNAR3]
,[DPNAR4]
FROM [HBGE_Reports].[dbo].[hub_DDJPFile] s
where exists (SELECT [ZGDCS]
FROM [HUB_DATA].[dbo].[SSCUSTP] d
where [ZGIDNO]=@a
and
s.DPACS=d.ZGDCS)
order by [DPVLDT] desc""", str(var))
rows = cursor.fetchall()
for i in range(a):
pub.sendMessage(i, rows[i].DPVLDT)
else:
self.test.SetLabel('False')
def afterOnbutton(self,e):
wx.CallAfter(self.Onbutton,e)
var = self.editquote1.GetValue()
if len(var)==9:
self.new = Childframe(None)
self.new.Show()
class Childframe(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent)
self.panel=wx.Panel(self)
self.windowSizer = wx.BoxSizer()
self.windowSizer.Add(self.panel, wx.ID_ANY, 13, wx.ALL | wx.EXPAND, 13)
pub.subscribe(self.amount, "amount")
for n in range(3):
pub.subscribe(self.row, n)
def amount(self, amount):
for n in range(amount.data):
[].append(wx.StaticText(self.panel, id=n, label='test', pos=(20, 30 * n)))
N = amount.data
return N
#I'm having problem here. I can't get N and I don't know how to SetLabel in the static text above
def row(self, row):
for n in range(N):
[].SetLabel(str(row.data))
if __name__=='__main__':
app=wx.App(False)
frame1=Childframe(None)
frame=Mainframe(None)
frame.Show()
app.MainLoop()