Hi. I'm trying to get my feet wet with programming and keep hitting some brick walls.
I basically want to look in a folder for certain filenames. If the files are there, I would like the term linked to the filename to be in a listbox.
I thought a dictionary would work:
Basically, a user selects a certain folder (using tkFileDialog.as kdirectory(). I then need a check to see if the filenames (the first part of the dictionary) are present. Then I would like the second part of the dictionary to be in the listbox.
I'm using tkinter.
Here's what I have:
Any help would be very appreciated. I'm trying to clear out the cobwebs.
Thanks
I basically want to look in a folder for certain filenames. If the files are there, I would like the term linked to the filename to be in a listbox.
I thought a dictionary would work:
Code:
dataset = { "File1.txt":"Picotiter Plate", "File2.txt":"KeyPass Wells", "File3.txt":"Reagent Lot numbers", "File4.txt":"Insert other trackable item"}
I'm using tkinter.
Here's what I have:
Code:
#! /usr/bin/env python from Tkinter import * import tkMessageBox import tkFileDialog import os class FileHandling: def datasets(self): dataset = { "File1.txt":"Picotiter Plate", "File2.txt":"KeyPass Wells", "File3.txt":"Reagent Lot numbers", "File4.txt":"Insert other trackable item"} class GUIFramework(Frame): """This is the GUI""" def __init__(self,master=None): """Initialize yourself""" """Initialise the base class""" Frame.__init__(self,master) """Set the Window Title""" self.master.title("454 Run Tracer") """Display the main window with a little bit of padding""" self.grid(padx=15, pady=15,sticky=N+S+E+W) self.CreateWidgets() def pathentry(self): path = tkFileDialog.askdirectory() path_selectedFolder = "%s" % path print "You chose %s" % path for file in os.listdir("%s" % path): self.FileList.insert(END, file) if FileHandling.dataset() in os.listdir("%s" %path): #Having trouble #here "" self.DataTypes.insert(END, WHAT GOES HERE?""") #Trouble here #also def CreateWidgets(self): """Create the buttons """ self.Instructions = Label(self, text="First, select a folder --->") self.Instructions.grid(row=0, column=0) self.btnDirectory = Button(self, text= "Select Run Folder", fg= 'blue', command=self.pathentry) self.btnDirectory.grid(row =0, column = 2, columnspan= 4, sticky = E+W) self.btnSelectAll = Button(self, text="Select All", fg='blue') #command = self.select_all self.btnSelectAll.grid(row=8, column = 2) self.btnCollectData = Button(self, text = "Collect Data" ,fg= "blue") # command = self.CollectData) self.btnCollectData.grid(row =8, column = 3) """Create a frame to separate the buttons from the listbox""" spaceframe = Frame(self, height= 5) spaceframe.grid(row=4, column = 1) self.FileListLabel = Label(self, text= "Select Data to Collect: ") self.FileListLabel.grid(row = 3, column = 0) """Create the Listbox Widget""" scrollbarV = Scrollbar(self, orient = VERTICAL) scrollbarH = Scrollbar(self, orient = HORIZONTAL) self.FileList= Listbox(self, selectmode= MULTIPLE , width= 40 , yscrollcommand=scrollbarV.set , xscrollcommand=scrollbarH.set , relief= SUNKEN , takefocus = 0 , borderwidth = 1 , state= NORMAL , cursor = "arrow") self.FileList.grid(row=5, column = 0, columnspan = 7, sticky = N + W + S + E) scrollbarV.grid(row= 5, column = 7, sticky = N + S) scrollbarV.config(command = self.FileList.yview) scrollbarH.grid(row = 6, column = 0, columnspan = 10, sticky = E+W) scrollbarH.config(command= self.FileList.xview) self.DataTypes = Listbox(self, selectmode=MULTIPLE , width=40 , yscrollcommand=scrollbarV.set , xscrollcommand=scrollbarH.set , relief=SUNKEN , takefocus= 0 , borderwidth=1 , state= NORMAL , cursor = "arrow") self.DataTypes.grid(row=5, column = 3, columnspan=6, sticky= N + W + S + E) if __name__ == "__main__": guiFrame = GUIFramework() guiFrame.mainloop()
Any help would be very appreciated. I'm trying to clear out the cobwebs.
Thanks
Comment