我試圖制作一個 gui,但我不斷收到這些錯誤。我查看了這些問題,但沒有一個有效。我嘗試了任何東西,但它們不起作用。如果你知道如何解決它,請幫助我。
代碼:
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()
uj5u.com熱心網友回復:
而不是son.width(),嘗試son.size[0]然后你會擺脫TypeError: 'int' object is not callable
uj5u.com熱心網友回復:
使用 son.width 獲取影像的寬度。 https://pillow.readthedocs.io/en/stable/reference/Image.html
uj5u.com熱心網友回復:
好的,我嘗試在本地運行它,因為您的帖子沒有錯誤
結論 :
使用不帶括號的son.width和son.height,它將起作用
呼叫 son.width() 相當于 3() (如果寬度等于 3)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/453022.html
下一篇:切換到較舊的提交而不更改任何內容
