gpt4 book ai didi

wxPython 一次选择多个项目 Listctrl

转载 作者:行者123 更新时间:2023-12-03 06:38:37 24 4
gpt4 key购买 nike

我正在尝试创建一个自定义 wxPython 小部件。这将允许用户从左侧列表中选择多个项目并将它们移动到右侧列表。我只是坚持从列表中选择多个项目。这是我想要实现的屏幕截图:

Multichoice Select on a panel

这是我的代码(它刚刚开始,因为没有清理):

import wx

########################################################################
class Car:
""""""

#----------------------------------------------------------------------
def __init__(self, id, model, make, year):
"""Constructor"""
self.id = id
self.model = model
self.make = make
self.year = year


########################################################################
class MyForm(wx.Frame):

#----------------------------------------------------------------------
def __init__(self):
wx.Frame.__init__(self, None, wx.ID_ANY, "Tutorial", size=(800,600))

# Add a panel so it looks the correct on all platforms
panel = wx.Panel(self, wx.ID_ANY)

ford = Car(0, "Ford", "F-150", "2008")
chevy = Car(1, "Chevrolet", "Camaro", "2010")
nissan = Car(2, "Nissan", "370Z", "2005")
fiat = Car(2, "Fiat", "F7Z", "2005")
fiat2 = Car(2, "Fiat", "punto", "2005")

sampleList = []

lb = wx.ListBox(panel,
size=(200, 150),
choices=sampleList)
self.oneadd = wx.Button(panel,-1, ">", pos=(110, 180))
self.multiadd = wx.Button(panel, -1,">>",pos=(200, 180))

lb2 = wx.ListBox(panel,
size=(200, 150),
choices=sampleList)

self.lb = lb
self.lb2 = lb2
lb2.Append(ford.make, ford)
lb.Append(chevy.make, chevy)
lb.Append(fiat.make, fiat)
lb.Append(fiat2.make, fiat2)
lb.Append(nissan.make, nissan)
lb.Bind(wx.EVT_LISTBOX, self.onSelect)


sizer = wx.BoxSizer(wx.HORIZONTAL)

sizer.Add(lb, 0, wx.ALL, 5)

sizer.Add(lb2, 0, wx.ALL, 5)
panel.SetSizer(sizer)

#----------------------------------------------------------------------
def onSelect(self, event):
""""""
print "You selected: " + self.lb.GetStringSelection()
obj = self.lb.GetClientData(self.lb.GetSelection())
text = """
The object's attributes are:
%s %s %s %s

""" % (obj.id, obj.make, obj.model, obj.year)
print text

# Run the program
if __name__ == "__main__":
app = wx.App(False)
frame = MyForm()
frame.Show()
app.MainLoop()

最佳答案

您需要在列表框中启用多重选择

lb = wx.ListBox(panel,
size=(200, 150),
style=wx.LB_MULTIPLE,
choices=sampleList)

洛克拉

关于wxPython 一次选择多个项目 Listctrl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27228119/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com