I have the following code where I'm trying to allow the user to open a text file and once the user has selected it, I would like the code to read it (this isn't a finished block of code, just to show what I'm after).
However, I'm having difficulties either using tkFileDialog.askopenfilename and adding 'mode='rb'' or using the code like below and using read where it produces an error.
Does anyone know how I can arrange to do this as I don't wish to have to type Tkinter.'module' for each item such as Menu and Listbox. Beginner to Tkinter and a bit confused! Thanks for the help!
from Tkinter import *
from tkFileDialog import askopenfilename # Open dialog box
fen1 = Tk() # Create window
menu1 = Menu(fen1)
filename = askopenfilename(filetypes=[("Text files","*.txt")])
txt = filename.read()
AttributeError: 'unicode' object has no attribute 'read'
askopenfilename only returns a file name, what you wanted was
askopenfile which accepts a
mode parameter and opens the file for you.