-3

I'm trying to transform a method into a int (i need to divide the method value for 2)

width = int(post.width) / 2

height = int(post.height) / 2

but it gives me this error:

TypeError: int() argument must be a string, a bytes-like object or a number, not 'method'

Is there any method to do it?

Edit: For those who're trying to help me, i want to import an image (with Pil, tkinter) but with the half of his size.

post1 = Image.open(directory)

width = int(post.width) / 2

height = int(post.height) / 2

canvas=Canvas(root,width=width,height=height)
canvas.create_image(0,0,anchor=NW,image=post)
canvas.pack(padx=20, pady=20)

Also, if you need it, i provide you the complete script:

from minio import Minio
import tkinter as tk
from tkinter import *
from PIL import Image, ImageTk
import random
import os

root = Tk()
root.title("Ripetra")

width_value = root.winfo_screenwidth()
height_value = root.winfo_screenheight()

minio = Minio('myip',
                access_key='key',
                secret_key='key',
              )

immagini = minio.list_objects('ripetra', recursive=True)
names = [img2.object_name for img2 in immagini]
image = random.choice(names)
imagecanvas = minio.fget_object("ripetra", image, "cont/ft/" + image)

dir = os.path.join("cont/ft/", image)

post1 = Image.open(dir)

resized = post1.resize((width_value, height_value), Image.ANTIALIAS)

post = ImageTk.PhotoImage(resized)

width = int(post.width()) / 2

height = int(post.height()) / 2

canvas=Canvas(root,width=width,height=height)
canvas.create_image(0,0,anchor=NW,image=post)
canvas.pack(padx=20, pady=20)

root.mainloop()
  • 2
    Why do you need to transform a method to int? I think you are looking to divide the value returned by the method – pecey Jul 01 '20 at 15:00
  • Would you want `width = int(post.width()) / 2`? (note the parens to *call* the method) – Serge Ballesta Jul 01 '20 at 15:02
  • Can you tell us more about post? Is this a numpy array? A custom class? Either way, please provide us with a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) so we can best help you. – Michael Delgado Jul 01 '20 at 15:05
  • these might help: https://stackoverflow.com/questions/3786881/what-is-a-method-in-python and https://stackoverflow.com/questions/33140162/int-argument-must-be-a-string-a-bytes-like-object-or-a-number-not-method – jmunsch Jul 01 '20 at 15:10

2 Answers2

1

You should put () after each method name, since what you want to do is call the method. What your code is currently trying to do is convert a piece of python code to an integer which is non-sensical.

Try doing this :

width = int(post.width()) / 2

height = int(post.height()) / 2

All though I think actually you probably need this :

width = int(post.width() / 2)

height = int(post.height() / 2)

That is you want to convert the value to an integer after the division in case one of the values returned is odd.

Tony Suffolk 66
  • 9,358
  • 3
  • 30
  • 33
0

You probably forgot parenthesis after .width and .height :

width = int(post.width()) / 2
height = int(post.height()) / 2
totok
  • 1,436
  • 9
  • 28
  • Yes! It works! But actually the image get cropped: https://imgur.com/9HwtTj3 – MATTIA ANTONACCI Jul 01 '20 at 15:05
  • Yes - it will get cropped - you are saying you only want the first 1/2 of the width and the first half of the height - i.e. the top 1/4. If you want to resize it, then you will need to resize the image, using the right library. – Tony Suffolk 66 Jul 01 '20 at 15:07