0

Hi All,

I am working on a little side project for myself. i have created an interface which contains two listboxes and a few buttons. Clicking on each button would load separate csv files and they would populate in listbox 1. This is as far as i have gotten, what i want to do is when i click on an item for it to be moved to listbox 2 and then have the ability to create a new csv file with the newly gathered items. Below is the code showing as far as i have gotten.

import csv
from Tkinter import *
import Tkinter as tk
import tkMessageBox

def passfile(value):
    listbox.delete(0, END)
    f = open(value)
    csv_fi = csv.reader(f)
    for x in csv_fi:
        listbox.insert(tk.END, x[0])
    f.close()

root = tk.Tk()

# Create a GUI window named Colors File Generator
root.title("Colors File Generator")
root.option_add('*font', ('verdana', 12, 'bold'))
root.geometry('{}x{}'.format(680,800))

#Create two list boxes next to each other.
listbox = tk.Listbox(root, width=40, height=10)
listbox.grid(row=0, column=1)
listbox1 = tk.Listbox(root, width=40, height=10)
listbox1.grid(row=0, column=2)

#Create a scrollbar for the first listbox
yscroll = tk.Scrollbar(command=listbox.yview, orient=tk.VERTICAL)
yscroll.grid(row=0, column=0, sticky=tk.N+tk.S)
listbox.configure(yscrollcommand=yscroll.set)

#Create a scrollbar for the second listbox
yscroll1 = tk.Scrollbar(command=listbox1.yview, orient=tk.VERTICAL)
yscroll1.grid(row=0, column=3, sticky=tk.N+tk.S)
listbox1.configure(yscrollcommand=yscroll1.set)

#Create the buttons for the Specific Brands
button1 = tk.Button(root, text='List1', command= lambda:passfile('attendees.csv'))
button1.grid(row=1, column=1, sticky=tk.W)

button2 = tk.Button(root, text='List2' , command= lambda:passfile('attendees2.csv'))
button2.grid(row=2, column=1, sticky=tk.W)

button3 = tk.Button(root, text='List3' , command= lambda:passfile('attendees2.csv'))
button3.grid(row=3, column=1, sticky=tk.W)

button4 = tk.Button(root, text='List4' , command= lambda:passfile('attendees2.csv'))
button4.grid(row=4, column=1, sticky=tk.W)

button5 = tk.Button(root, text='List5' , command= lambda:passfile('attendees2.csv'))
button5.grid(row=5, column=1, sticky=tk.W)

button6 = tk.Button(root, text='List6' , command= lambda:passfile('attendees2.csv'))
button6.grid(row=6, column=1, sticky=tk.W)

#Create Button to save, download and delete the selected colors
button7 = tk.Button(root, text="Save Values", command=lambda:Save_Values)
button7.grid(row=1, column=2, sticky=tk.E)

#Create Button to Generate and save the file
button8 = tk.Button(root, text="Save File", command=lambda:Save_file)
button8.grid(row=2, column=2, sticky=tk.E)

button9 = tk.Button(root, text="Delete", command=lambda:Delete)
button9.grid(row=3, column=2, sticky=tk.E)
root.mainloop()
2
Contributors
1
Reply
25
Views
1 Year
Discussion Span
Last Post by G_S
0

Well, I would first store the loaded content in a list, then populate the listbox with it.
Second, I would create a buton whose associated function performs a curselection() to get the selected items, then check if they exist in list 2 and if not, place them there. Finally this function would create a new file (you can either do it manually or use a csv library for that) and write the second list to it.

I did not understand, however, if you want to make the new file using the entire content of the second listbox or just the selected items.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.