Home > Net >  TypeError: 'int' object is not callable on tkinter
TypeError: 'int' object is not callable on tkinter

Time:03-31

I was trying to make a gui but i keep getting these errors. I looked at the questions but none have worked. I tried anything but they dont work. if you know how to fix it, please help me.

Code:

from tkinter import *
from  PIL import ImageTk,Image




master = Tk()
master.title("")
master.attributes("-fullscreen", True)

width1 = master.winfo_screenwidth()
height1 = master.winfo_screenheight()
print (width1/2, height1/2)


canvas = Canvas(master, height=height1 , width=width1)
canvas.pack()



foto = Image.open("harita_50.png")
print(foto)
son = foto.resize((round((foto.width*(2/3))), round((foto.height*(2/3)))))


canvas.create_image(((width1-son.width())/2),((height1-son.height())/15),anchor=NW,image=son) 

master.mainloop()

CodePudding user response:

instead of son.width(), try son.size[0] then you will get rid of TypeError: 'int' object is not callable

CodePudding user response:

Use son.width to get the width of the Image. https://pillow.readthedocs.io/en/stable/reference/Image.html

CodePudding user response:

Ok i tried to run it on my local because there is no errors on your post

conclusion :

use son.width and son.height without the parentheses and it will work

calling son.width() is equivalent of 3() (if the width equals to 3)

  • Related