从wxpython中的另一个textcrl(item[])将值设置为textcrl(字符串)

2024-09-30 01:36:45 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在替换textcrl的值(名称:控制)从另一个文本Ctrl(名称:controlz). 到目前为止我已经做到了。在

def replace(self, event):
    newtext = tokenize_editor_text(self.controlz.GetValue())
    text = tokenize_editor_text(self.control.GetValue())
    for word in text:

        if (word == misspelled_list[0]):
            text[text.index(word)] = newtext
            corrected = ' '.join(map(str,text))
            self.control.SetValue(corrected)
            print corrected

例如,当(self.controlz)中有一个输入( Chony),而要替换(self.control)中的另一个单词(choni),它将替换[u'chony']。即使我也用过' '.join(map(str,text))。我怎么能得到相同的值(chony)而不是[u'chony'] 任何解决方案都值得赞赏。 非常感谢


Tags: textself名称mapeditorcontrolwordjoin
1条回答
网友
1楼 · 发布于 2024-09-30 01:36:45

如果在列表或元组上调用str,它将显示列表内部值的repr

str(["1","2"]) #==> '[u"1",u"2"]'

这个电话

^{pr2}$

返回一个我认为类似[u"chony"]的列表

然后将该列表值设置为内部的列表索引

text[i] = newtext #==> text[i] = [u"chony",]  ... => text = [[u"chony"],[...]]

然后调用每个文本项的字符串

map(str, text) # which calls str on the array that you set as the indexes 

如果在newtext中始终只有一个元素,则可以只分配第0个索引

text[i] = newtext[0]

相关问题 更多 >

    热门问题