0

( ボタン) をクリックしたときにユーザーの入力 a[] から値を取得する空のリストがあります。リストの最初の要素を出力する必要があります。次に、ユーザーが同じボタンをもう一度クリックしたときに、2 番目の要素が必要です。印刷するリストなど。これがボタンです

self.button3 = wx.Button(self.panel, label="add word",size=(100,50),pos=(650,220))
self.button3.Bind(wx.EVT_BUTTON, self.buttonloop)

これは、ボタンがクリックされるたびに呼び出したい関数です

def buttonloop(self,event):
    os.chdir('d:/KKSC')
    dic = getDic()
    print dic[0], dic[1], dic[2]
    text = tokenize_editor_text(self.control.GetValue())        
    a =[]
    for word in text:
        if word not in dic:
             misspelled = word
             a.append(misspelled)
             for item in a:
                print(item + " is an ape")
                currentitem = item
                b=a[item]
                c=item.index
                nextitem = a[c + 1]
                print nextitem
        # here I want to call the function again if the button clicked again

これまでのところ、私にはうまくいきません。私をよく理解していない場合は、投稿を再編集するか、コメントでさらに説明します

4

1 に答える 1

0

発電機を試してみませんか?

def buttonloop(self,event):
    os.chdir('d:/KKSC')
    dic = getDic()
    print dic[0], dic[1], dic[2]
    text = tokenize_editor_text(self.control.GetValue())        

    try:  ##Exception handler for first occurence(will also cause the list to loop)
        print self.wordlist.next()
    except:
        self.wordlist = getwordlist(text,dic)
        print self.wordlist.next()

def getwordlist(self,text,dic):
    a = []
    for word in text:
        if word not in dic:
            misspelled = word
            a.append(misspelled)
    for item in a:
        yield item
于 2015-06-05T22:57:18.310 に答える