체크 된 문자열 또는 체크리스트에서 정수를 가져 오려고합니다. 나는 그것을 어디에서나 얻을 수는 없다. 아래의 코드에서는 un-commented 코드 묶음을 볼 수 있습니다. 나는 어떤 제안이 그것과 관련이있을 때를 대비하여 나는 그들을 떠날 것이라고 생각했다. 나는 GUI 프로그래밍과 wx에있어서 아주 새로운 것이다. 당신의 도움을 주셔서 감사합니다.wxpython의 checklistbox에서 데이터를 가져 오는 방법을 이해할 수 없습니다.
import wx
class Panel1(wx.Panel):
def __init__(self, parent, log):
wx.Panel.__init__(self, parent, -1)
allLoc = ['One', 'Two', 'Three', 'Four']
wx.StaticText(self, -1, "Choose:", (45, 15))
citList = wx.CheckListBox(self, -1, (60, 50), wx.DefaultSize, allLoc)
#self.Bind(wx.EVT_CHECKLISTBOX, self.GetChecks, citList)
#h = citList.GetChecked()
#cities =()
#v = cities.append(h)
#print h
pos = citList.GetPosition().x + citList.GetSize().width + 25
nextBtn = wx.Button(self, -1, "Next", (pos, 50))
self.Bind(wx.EVT_BUTTON, wx.EvyRadBox2, nextBtn)
#def GetChecks(self, event):
#r = citList.GetId()
#print r
#def printChecks(self, event):
#l = event.CetCheckStrings()
#print l
def EvyRadBox2(self, event):
filepath2 = "c:\\logger2.txt"
file1 = open(filepath2, 'w')
file1.write('%d \n' % event.GetChecked())
file1.close()
app = wx.PySimpleApp()
frame = wx.Frame(None, -1, "Charlie")
Panel1(frame,-1)
frame.Show(1)
app.MainLoop()
************************** 편집 **************** ****************
그래서 내가 처음에 이런 짓을이
import wx
checkedItems = []
class citPanel(wx.Panel):
def __init__(self, parent, id):
wx.Panel.__init__(self, parent, id)
allLoc = ['One', 'Two', 'Three', 'Four']
wx.StaticText(self, -1, "Choose:", (45, 15))
citList = wx.CheckListBox(self, -1, (60, 50), wx.DefaultSize, allLoc)
checkedItems = [i for i in range(citList.GetCount()) if citList.IsChecked(i)]
class nextButton(wx.Button):
def __init__(self, parent, id, label, pos):
wx.Button.__init__(self, parent, id, label, pos)
class checkList(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title, size=(400, 400))
panel = citPanel(self, -1)
nextButton(panel, -1, 'Ok', (275, 50))
self.Bind(wx.EVT_BUTTON, self.Clicked)
self.Centre()
self.Show(True)
def Clicked(self, event):
print checkedItems
event.Skip()
app = wx.App()
checkList(None, -1, 'Charlie')
app.MainLoop()
처럼 내 코드를 변경, 내가 버튼을 클릭하면, 그것은을 wxstdout에 정의되지 않은 전역 이름을 던졌습니다. 지금은 빈 목록을 보여줍니다, 나는 상단에있는 checkedlist을 추가, 그것은 처음에는 아무도 없었다., 어떤 도움을, 언제나, 감사를해야한다 미리
단추에 바인딩 할 수 있습니까? – Kevin
물론,'self.Bind (wx.EVT_BUTTON, self.EvyRadBox2, nextBtn)'와 비슷한 것을 쓸 수 있습니다 ('self.EvyRadBox2'에서 체크 된 아이템을 얻고 있다고 가정). – Li0liQ
콘솔을 연 상태에서 실행하면 볼 수있는 것은 빈 튜플()입니다. 나는 수표가 읽히고 있는지, 나는 그들을 다른 것으로 전하기를 원할 것인가, 나는 단지 그들을 붙잡고 있다고 생각하지 않는다. – Kevin