Nov-13-2020, 02:51 PM
Hello,
I am trying to read a file from askopenfilename outside the function. I am getting blank file name. What am I doing wrong? Here is my code.
I am trying to read a file from askopenfilename outside the function. I am getting blank file name. What am I doing wrong? Here is my code.
from tkinter import * from tkinter import filedialog def on_openfile(): global pic pic = filedialog.askopenfilename() root = Tk() menubar = Menu(root) root.config(menu=menubar) file_menu = Menu(menubar) file_menu.add_command(label="Open", command=on_openfile) file_menu.add_command(label="Exit", command=root.destroy) menubar.add_cascade(label="File", menu=file_menu) f = open(pic) print(f.read()) root.mainloop()Thanks.