Home:ALL Converter>With Tkinter trying to open a text file in Text() widget

With Tkinter trying to open a text file in Text() widget

Ask Time:2019-11-21T02:38:40         Author:Grimnack

Json Formatter

Guys i was trying to open a text file in Text() widget.The problem is when i click Open File,i get the file dialog,and when i select a file and click open,i get TypeError.Please advise.Thank you. This is the relevant code

open = PhotoImage(file='ico/open.gif')
filemenu.add_command(label="Open",accelerator='Ctrl + O',compound='left',image=open,command=open_file)
file_name = None

def open_file(event=None):
    input_file_name = tkinter.filedialog.askopenfilename(defaultextension=".txt",filetypes=[("All Files", "*.*"), ("Text Documents", "*.txt")])
    if input_file_name:
        global file_name
        file_name = input_file_name
        root.title('{} - {}'.format(os.path.basename(file_name), PROGRAM_NAME))
        content.delete(1.0, END)
        with open(file_name) as _file:
            content.insert(1.0, _file.read())

And i get this error

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Users\Crystal\AppData\Local\Programs\Python\Python37\lib\tkinter\__init__.py", line 1705, in __call__

    return self.func(*args)
  File "C:\Users\Crystal\Desktop\New folder\text_ed\ui.py", line 61, in open_file
    with open(file_name) as _file:
TypeError: 'PhotoImage' object is not callable

Author:Grimnack,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/58961239/with-tkinter-trying-to-open-a-text-file-in-text-widget
yy