Jul-11-2018, 11:55 AM
The code below works fine if the list (=test_list) is defined as test_list=['aaa','xxxxxx','a1a1a11',.....].
When the test_list gets values from an sql table (lines 41-46), there is TypeError: descriptor 'lower' requires a 'str' object but received a 'tuple'.
Instead of the code line #27 (-> data = sorted(data, key=str.lower)), i tried sth like: data = sorted(data, key=lambda x: x[0]), data = sorted(data, key=lambda x: (x[0].lower())) but i can't find any solution.
The fetchall data has the format: [('FCZ204613AR',), ('FCZ204613AS',), ('FCZ204613AT',), ('FCZ204613AV',), ('FCZ204613AY',),....]
When the test_list gets values from an sql table (lines 41-46), there is TypeError: descriptor 'lower' requires a 'str' object but received a 'tuple'.
Instead of the code line #27 (-> data = sorted(data, key=str.lower)), i tried sth like: data = sorted(data, key=lambda x: x[0]), data = sorted(data, key=lambda x: (x[0].lower())) but i can't find any solution.
The fetchall data has the format: [('FCZ204613AR',), ('FCZ204613AS',), ('FCZ204613AT',), ('FCZ204613AV',), ('FCZ204613AY',),....]
import tkinter as tk import cx_Oracle def on_keyrelease(event): # get text from entry value = event.widget.get() value = value.strip().lower() # get data from test_list if value == '': data = test_list else: data = [] for item in test_list: if value in item.lower(): data.append(item) # update data in listbox listbox_update(data) def listbox_update(data): # delete previous data listbox.delete(0, 'end') # sorting data data = sorted(data, key=str.lower) # put new data for item in data: listbox.insert('end', item) def on_select(event): # display element selected on list print('(event) previous:', event.widget.get('active')) print('(event) current:', event.widget.get(event.widget.curselection())) print('---') # --- main --- connstr='SOLVATIO/SOLVATIO@localhost' conn = cx_Oracle.connect(connstr) cursw1 = conn.cursor() cursw1.execute("select SERIAL_NUMBER from customer_MCM") result1=cursw1.fetchall() test_list=list(result1) root = tk.Tk() entry = tk.Entry(root) entry.pack() entry.bind('<KeyRelease>', on_keyrelease) listbox = tk.Listbox(root) listbox.pack() #listbox.bind('<Double-Button-1>', on_select) listbox.bind('<<ListboxSelect>>', on_select) listbox_update(test_list) root.mainloop()