我有一个从 SQL 数据库中提取的数据,然后放入数据帧中,然后转换为列表。我正在创建一个 GUI,它可以让您选择零件号,然后根据选择的零件号更新数据库的部分内容。但是,我在整个列表框中得到了一个选择。如何将列表分解为每个数字的单个选择?我已经包含了整个 GUI 并更改了一些内容,因此它应该可以独立工作。列表的长度将发生巨大变化,因此我不能单独附加每个选择。
GUI 显然尚未完成或格式正确,因此请耐心等待。
import wx
import wx.adv
import sqlalchemy
from six.moves import urllib
import pandas as pd
#Reads the SQL Column to use for the dropdown menu
params = urllib.parse.quote_plus("Driver={ODBC Driver 18 for SQL Server};"
"Server=SERVER;"
"Database=DB;"
"Trusted_Connection=yes;"
"TrustServerCertificate=yes"
)
engine = sqlalchemy.create_engine("mssql+pyodbc:///?odbc_connect=%s" % params)
engine.connect()
#Gets list of Part Numbers for the menubox as well as matching to SQL DF
sqlread = pd.read_sql_query('''SELECT * FROM Shortage''',engine)
pndf = pd.DataFrame(sqlread, columns = ['PN'])
pndf = pndf[pndf.PN != None]
dflist = pndf.to_string(index=False,header=0)
#I'd just make your own list here to get similar results, but I want to demonstrate that I'm pulling the list from a SQL server
print(dflist)
class compwin(wx.Frame):
def __init__(self):
wx.Frame.__init__(self,None,-1,'Shortage Sheet Compiler v0.1',
size=(400,300))
panel = wx.Panel(self,-1)
#textbox printout
#Prompts for Update Field
wx.TextCtrl(panel,value = "Update What Part?",size=(100,20),pos=(25,20),style=wx.TE_READONLY|wx.BORDER_NONE)
#Text Boxes for Update Field
Combobox = wx.ListCtrl(panel, wx.ID_ANY, size=(125,125),pos=(20,40))
Combobox.EnableCheckBoxes()
Combobox.Append([dflist])
if __name__ == '__main__':
app = wx.App()
frame = compwin()
frame.Show()
app.MainLoop()
我希望列表“dflist”中的每个选择都可以单独选择。如何将列表分成单独的条目,或者让 ListCtrl 将它们识别为单独的条目?
目前还不完全清楚为什么你会遇到问题,除了你没有用
style=wx.LC_REPORT
声明控件之外,可能就是这么简单。
import wx
dflist = [["123","abc"],["456","def"],["789","ghi"],["132","jkl"],["465","mno"]]
class compwin(wx.Frame):
def __init__(self):
wx.Frame.__init__(self,None,-1,'Shortage Sheet Compiler v0.1',
size=(400,300))
panel = wx.Panel(self,-1)
#textbox printout
#Prompts for Update Field
wx.TextCtrl(panel,value = "Update What Part?",size=(150,20),pos=(25,20),style=wx.TE_READONLY|wx.BORDER_NONE)
#Text Boxes for Update Field
Combobox = wx.ListCtrl(panel, wx.ID_ANY, size=(300, -1),pos=(25, 50), style=wx.LC_REPORT)
Combobox.InsertColumn(0, "Item", wx.LIST_FORMAT_RIGHT)
Combobox.InsertColumn(1, "Name", wx.LIST_FORMAT_RIGHT)
for item in dflist:
Combobox.Append((item[0],item[1]))
if __name__ == '__main__':
app = wx.App()
frame = compwin()
frame.Show()
app.MainLoop()