Tkinter Gui to read in csv file and generate buttons based on the entries in the first row
Posted
by
Thomas Jensen
on Stack Overflow
See other posts from Stack Overflow
or by Thomas Jensen
Published on 2012-07-03T14:21:41Z
Indexed on
2012/07/06
21:16 UTC
Read the original article
Hit count: 260
I need to write a gui in Tkinter that can choose a csv file, read it in and generate a sequence of buttons based on the names in the first row of the csv file (later the data in the csv file should be used to run a number of simulations).
So far I have managed to write a Tkinter gui that will read the csv file, but I am stomped as to how I should proceed:
from Tkinter import *
import tkFileDialog
import csv
class Application(Frame):
def __init__(self, master = None):
Frame.__init__(self,master)
self.grid()
self.createWidgets()
def createWidgets(self):
top = self.winfo_toplevel()
self.menuBar = Menu(top)
top["menu"] = self.menuBar
self.subMenu = Menu(self.menuBar)
self.menuBar.add_cascade(label = "File", menu = self.subMenu)
self.subMenu.add_command( label = "Read Data",command = self.readCSV)
def readCSV(self):
self.filename = tkFileDialog.askopenfilename()
f = open(self.filename,"rb")
read = csv.reader(f, delimiter = ",")
app = Application()
app.master.title("test")
app.mainloop()
Any help is greatly appreciated!
© Stack Overflow or respective owner