2012-01-26 4 views
2

timezone1 목록 상자에서 zone_list 중 하나를 클릭하면 해당 문자열을 time_zones2 목록 상자에 삽입하고 그 후에 다른 선택 항목을 선택하면 두 번째 선택 항목을 timezones2 목록 상자의 두 번째 줄에 추가하고 싶습니다. 그런 다음 이전에 time_zone2 목록 상자에서 한 선택 사항 중 하나를 클릭하면 해당 선택 항목을 삭제하려고합니다. 내가 아래에 한 일을 봐>를 choice- 클릭 listbox2wxpython : 한 목록 상자에서 다른 목록 상자에 여러 문자열 삽입

에서 그 선택을 삭제 listbox2>를 choice-에 에 ListBox1를 클릭 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() 

답변

0

나는 코드를 가져와 필요한 것을 추가했습니다. wx.ListBox.Set (items)는 항목 목록을 필요로하므로 단일 문자열을 전달하면 문자열의 각 문자를 개별 항목으로 간주합니다.

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)) 
     self.second_zones = [] 
     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.OnSelectFirst, self.time_zones) 
     self.Bind(wx.EVT_LISTBOX, self.OnSelectSecond, self.time_zones2) 


    def OnSelectFirst(self, event): 
     index = event.GetSelection() 
     time_zone = str(self.time_zones.GetString(index)) 
     self.second_zones.append(time_zone) 
     self.time_zones2.Set(self.second_zones) 


    def OnSelectSecond(self, event): 
     index = event.GetSelection() 
     time_zone = str(self.time_zones2.GetString(index)) 
     self.second_zones.remove(time_zone) 
     self.time_zones2.Set(self.second_zones)   


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() 
+0

매우 정확하게 일치하는 것이 무엇인지 찾고 있습니다 !!!! – TLSK

관련 문제