I have a hard time using file handling when I combine my main function and the gui code. I am new to both OOP and GUI (TKinter). I want my program to have a button and will open a file. Then this file will be used in the main() function and then it does what is tasked to do. Here is a part of the code:
class GuiFrame1(Frame):
def __init__ (self):
Frame.__init__(self)
self.master.geometry("500x500")
self.pack(expand = 1, fill = BOTH)
self.FileOpenerButton = Button(self,\
text = "Open File", command = self.OpenFile)
self.FileOpenerButton.pack()
def OpenFile(self):
inputFile = tkFileDialog.askopenfile()
inputFile.close()
def main():
with open ("LotData1.txt", "r") as fp:
sideList = []
for i in fp:
tmp = i.strip().split()
sideList.append([tmp[0], tmp[1], float(tmp[2])])
So it is like I want to remove the with open ("LotData1.txt", "r") as fp: and it shall use the file that I selected with the Gui. Here's the full code if someone is interested. http://pastebin.com/PGdXk8Bx
The reason why I used the with open function is because I tried to see if my main() function works and if it calculates the needed things for the output, and then I am trying to implement it with TKinter.