새로운 언어를 배우면서 알 수없는 단어를 관리 할 수있는 간단한 GUI 응용 프로그램을 만들었습니다. Vocabulary라는 앱은 C#으로 작성되었으며 XML 문서에서 단어를로드/저장합니다. 최근에 Windows에서 Linux로 전환 한 이래로 Python을 사용하여 응용 프로그램을 다시 작성하고 있습니다.내 애플리케이션에 자동 검색 기능을 구현하는 방법은 무엇입니까?
그럼에도 불구하고 내 응용 프로그램에 검색 기능을 구현하는 데 문제가 있습니다. 텍스트 위젯에 단어를 입력하면 자동으로 목록 상자에 표시됩니다. 응용 프로그램에서 수행 할 작업을 수행하기 위해 텍스트 위젯의 텍스트 변경 이벤트를 처리해야한다는 것을 알고 있습니다. 여기
내 원래의 C# 방법입니다 :private void txt_Search_TextChanged(object sender, EventArgs e)
{
if (txt_Search.Text != "")
{
for (int i = listView1.Items.Count - 1; i >= 0; i--)
{
var item = listView1.Items[i];
if (item.Text.ToLower().Contains(txt_Search.Text.ToLower()))
{
item.BackColor = SystemColors.Highlight;
item.ForeColor = SystemColors.HighlightText;
}
else
{
listView1.Items.Remove(item);
}
}
if (listView1.SelectedItems.Count == 1)
{
listView1.Focus();
}
}
else
{
LoadWords();
RefreshAll();
foreach (ListViewItem item in listView1.Items)
{
item.BackColor = SystemColors.Window;
item.ForeColor = SystemColors.WindowText;
}
}
}
... 그리고 여기에 지금까지 내 파이썬 함수이다 :
:def txt_Search_text_changed(self, event = None):
if self.get_search() != None:
i = self.listBox.size() - 1
for x in range(i, 0, -1):
item = self.listBox.get(0, "end")[i]
if self.get_search().lower() in item.lower():
self.listBox.itemconfig(i, {'bg': 'red'})
else:
self.listBox.delete(item)
if len(self.listBox.curselection()) == 1:
self.listBox.focus()
else:
self.load_words()
self.refresh_all()
for item in self.listBox.get(0, "end"):
self.listBox.itemconfig(i, {'bg': 'white'})
나는 파이썬의 상응하는 무엇을 모른다
listView1.Items[i];
listView1.Items
당신은 당신이 자동으로 추가되어야 함을 의미합니까, "자동으로 목록 상자에 표시"라고 기존 목록 상자? 또는 단어가 이미 목록 상자에 있으며 검색 기능이 목록 상자를 검색하고 검색된 단어를 강조 표시해야한다고 말하고 있습니까? –
단순히 목록 상자를 검색하여 검색된 단어를 강조 표시해야합니다. –
'self.listBox.get (0, "end") [i]'할 이유가 없습니다. 이 문서를 읽으면'self.listBox.get (i)'가 정상적으로 작동한다는 것을 알 수있다. –