python筛选csv数据_Tkinter搜索/筛选条 - csv文件

如果我得到你的问题吧,你不会是这样的:

from Tkinter import *

# First create application class

class Application(Frame):

def __init__(self, master=None):

Frame.__init__(self, master)

self.lbox_list = [('Adam', 'Mitric'),

('Lucy', 'Devic' ),

('Bob' , 'Freamen'),

('Amanda', 'Ling'),

('Susan', 'Cascov')]

self.pack()

self.create_widgets()

# Create main GUI window

def create_widgets(self):

self.search_var = StringVar()

self.search_var.trace("w", lambda name, index, mode: self.update_list())

self.entry = Entry(self, textvariable=self.search_var, width=13)

self.lbox1 = Listbox(self, width=20, height=15)

self.lbox2 = Listbox(self, width=20, height=15) # Second List Box. Maybe you can use treeview ?

self.entry.grid(row=0, column=0, padx=10, pady=3)

self.lbox1.grid(row=1, column=0, padx=10, pady=5)

self.lbox2.grid(row=1, column=1, padx=10, pady=5)

# Function for updating the list/doing the search.

# It needs to be called here to populate the listbox.

self.update_list()

def update_list(self):

search_term = self.search_var.get()

# Just a generic list to populate the listbox

self.lbox1.delete(0, END)

self.lbox2.delete(0, END) # Deletng from second listbox

passed = [] # Need this to check for colisions

for item in self.lbox_list:

if search_term.lower() in item[0].lower():

self.lbox1.insert(END, item[0])

self.lbox2.insert(END, item[1])

passed.append(item)

for item in self.lbox_list:

if search_term.lower() in item[1].lower() and item not in passed:

self.lbox1.insert(END, item[0])

self.lbox2.insert(END, item[1])

root = Tk()

root.title('Filter Listbox Test')

app = Application(master=root)

app.mainloop()

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值