title: Python3 open image with dialog box in Tkinter
body: <p>Am on a course in python3 from a book and it doesn't have any explaination on way i get this error when trying to open a image with a dialog bog (file explorer), to be clear the image can be open by using Image.open() but when i do open it with the file explore i get this:</p>
  <pre><code>&quot;C:\Users\Yoant\Documents\Python Program\Programs\Tkinter-Course\Open File dialog box\venv\Scripts\python.exe&quot; &quot;C:/Users/Yoant/Documents/Python Program/Programs/Tkinter-Course/Open File dialog box/main.py&quot;
  Traceback (most recent call last):
    File &quot;C:\Users\Yoant\Documents\Python Program\Programs\Tkinter-Course\Open File dialog box\main.py&quot;, line 16, in &lt;module&gt;
      my_img = ImageTk.PhotoImage(Image.open(root.filename))
    File &quot;C:\Users\Yoant\AppData\Local\Programs\Python\Python39\lib\site-packages\PIL\Image.py&quot;, line 2900, in open
      prefix = fp.read(16)
    File &quot;C:\Users\Yoant\AppData\Local\Programs\Python\Python39\lib\encodings\cp1252.py&quot;, line 23, in decode
      return codecs.charmap_decode(input,self.errors,decoding_table)[0]
  UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 246: character maps to &lt;undefined&gt;
  </code></pre>
  <pre><code># this is my code below:
  
  from tkinter import *
  from tkinter import filedialog
  from PIL import ImageTk, Image
  
  root = Tk()
  root.title(&quot;File Dialog box&quot;)
  
  # Return the name and location of the file.
  root.filename = filedialog.askopenfile(initialdir=&quot;/Pictures&quot;, title=&quot;select a file&quot;, filetypes=((&quot;png files&quot;, &quot;*.jpg&quot;),(&quot;all file&quot;, &quot;*.*&quot;)))
  
  # Display dir of file selected
  my_lbl = Label(root, text=root.filename).pack()
  
  # Display image
  my_img = ImageTk.PhotoImage(Image.open(root.filename))
  my_lbl2 = Label(image=my_img).pack()
  
  mainloop()
  </code></pre>