0

hello everyone i am working on a project about puzzle game. I had problem with uploading image to program by using tk.filedialog but i have this error

UnboundLocalError: cannot access local variable 'image' where it is not associated with a value

here is my code:

def select_image(): file_path = tk.filedialog.askopenfilename() if file_path: # Resmi 16 parçaya böl image = image.open(file_path) image = image.resize((400, 400)) image_list = [] for i in range(0, 400, 100): for j in range(0, 400, 100): piece = image.crop((i, j, i+100, j+100)) image_list.append(piece) 
1
  • 1
    image.open() makes no sense - you're only just defining image in that line of code, you can't use it to define itself! I think that should be Image.open(), referring to a class from the PIL or Pillow library. Commented Mar 24, 2023 at 13:44

1 Answer 1

0

I think you have a mistake here, to open an image by using tk.filedialog you need to use something like PIL.Image ( it seems you have mistaken it for image, which has the same name as your variable, so it is reported that image has been used even though undeclared). Change the code to:

from PIL import Image ... image = Image.open(file_path) ... 
Sign up to request clarification or add additional context in comments.

2 Comments

i wanna resize the image but i have this error AttributeError: module 'PIL.Image' has no attribute 'resize'
It can help you.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.