python 3.x - How to add columns to a tkinter.Listbox? -
i trying add these panda columns listbox
, read this:
new zealand nzd united states usd
etc.
i using pandas data .csv, when try , use loop add items list box using insert error
nameerror: name 'end' not defined
or nameerror: name 'end' not defined
using code:
def printcsv(): csv_file = ('testcur.csv') df = pd.read_csv(csv_file) print (df[['country','code']]) your_list = (df[['country','code']]) item in your_list: listbox.insert(end, item)
you turn csv file dictionary, use combined country , currency codes keys , codes values, , insert keys listbox
. code of current selection, can this: currencies[listbox.selection_get()]
.
listbox.selection_get()
returns key use currency code in currencies
dict.
import csv import tkinter tk root = tk.tk() currencies = {} open('testcur.csv') f: next(f, none) # skip header. reader = csv.reader(f, delimiter=',') country, code in reader: currencies[f'{country} {code}'] = code listbox = tk.listbox(root) key in currencies: listbox.insert('end', key) listbox.grid(row=0, column=0) listbox.bind('<key-return>', lambda event: print(currencies[listbox.selection_get()])) tk.mainloop()
Comments
Post a Comment