wxpython:将多个字符串从一个列表框插入到另一个列表框
当我单击 timezone1 列表框中的 zone_list 的选项之一时,我想将该字符串插入到 time_zones2 列表框中,如果我之后选择其他选项,我想将第二个选项添加到 timezones2 的第二行列表框。然后,当我单击之前对 time_zone2 列表框所做的选择之一时,我想删除该选择。
这就是我想做的: listbox1 单击一个选项 -> 将该选项插入到 listbox2 中 listbox2 单击一个选项 -> 从 listbox2 中删除该选项
看看我在下面做了什么:
import wx
from time import *
class MyFrame(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title, wx.DefaultPosition, (550, 350))
zone_list = ['CET', 'GMT', 'MSK', 'EST', 'PST', 'EDT']
panel = wx.Panel(self, -1)
self.time_zones = wx.ListBox(panel, -1, (10,100), (170, 130), zone_list, wx.LB_SINGLE)
self.time_zones.SetSelection(0)
self.time_zones2 = wx.ListBox(panel, -1, (10,200), (170, 400), '',wx.LB_SINGLE)
self.Bind(wx.EVT_LISTBOX, self.OnSelect)
def OnSelect(self, event):
index = event.GetSelection()
time_zone = self.time_zones.GetString(index)
self.time_zones2.Set(time_zone)
class MyApp(wx.App):
def OnInit(self):
frame = MyFrame(None, -1, 'listbox.py')
frame.Centre()
frame.Show(True)
return True
app = MyApp(0)
app.MainLoop()
When I click on one of the choices of the zone_list in timezone1 listbox, I want to insert that string in the time_zones2 listbox, and if I select an other choice after that, I want to add the second choice to the second line of the timezones2 listbox. Then, when I click one of the choices I have done before to the time_zone2 listbox, I want to delete that choice.
This is what I want to do:
listbox1 click on a choice->insert that choice in listbox2
listbox2 click on a choice->delete that choice from listbox2
Look what I have done below:
import wx
from time import *
class MyFrame(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title, wx.DefaultPosition, (550, 350))
zone_list = ['CET', 'GMT', 'MSK', 'EST', 'PST', 'EDT']
panel = wx.Panel(self, -1)
self.time_zones = wx.ListBox(panel, -1, (10,100), (170, 130), zone_list, wx.LB_SINGLE)
self.time_zones.SetSelection(0)
self.time_zones2 = wx.ListBox(panel, -1, (10,200), (170, 400), '',wx.LB_SINGLE)
self.Bind(wx.EVT_LISTBOX, self.OnSelect)
def OnSelect(self, event):
index = event.GetSelection()
time_zone = self.time_zones.GetString(index)
self.time_zones2.Set(time_zone)
class MyApp(wx.App):
def OnInit(self):
frame = MyFrame(None, -1, 'listbox.py')
frame.Centre()
frame.Show(True)
return True
app = MyApp(0)
app.MainLoop()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我拿了你的代码并添加了你需要的内容。请记住,wx.ListBox.Set(items) 需要一个项目列表,因此当您向它传递单个字符串时,它会将字符串中的每个字符视为单独的项目。
I took your code and added what you needed. Keep in mind that wx.ListBox.Set(items) expects a list of items, so when you pass it a single string, it will consider each character from the string as a separate item.