0
ListBoxを使用して検索GUIを作成しようとしています。入力した文字列と一致するデータがリストにある場合、リストボックスにデータを出力します。検索ボタンを使用してリストからデータを出力するpython
一致するデータを取得してListBoxに表示する際に問題が発生しています。リスト内のすべてのデータが表示されます。 Pythonの新機能以下は私が遠くまで持っているものです。あなたは、Python
if "dylan" in "bob dylan": # True
if "bob dylan".startswith("dylan"): # False
if "dylan" in "Bob Dylan": # False
if "dylan".lower() in "Bob Dylan".lower(): # True
の基礎を必要とする
おかげ
from tkinter import *
w = Tk()
liststuff = ["bob", "john", "theo", "bobby"]
l1 = Label(w, text='Name')
l1.grid(row=0, column=0)
title_text = StringVar()
e1 = Entry(w, textvariable=title_text)
e1.grid(row=0, column=1)
list1 = Listbox(w, height=0, width=35)
list1.grid(row=1, rowspan=4, columnspan=2)
sb1 = Scrollbar(w)
sb1.grid(row=1, column=3)
def search_command():
list1.delete(0, END)
for x in liststuff:
list1.insert(END, x)
list1.configure(yscrollcommand=sb1.set)
sb1.configure(command=list1.yview)
b1 = Button(w, text="Search", width=12, command=search_command)
b1.grid(row=0, column=4)
w.mainloop()
あなたの問題は、tkinterではなくPythonの基本です。 'A in B'または' A.startswith(B) 'ならば – furas