我想移动并调整tkinter画布图像对象的大小 . 它可以很好地移动图像 . 但使用绑定或按钮调整图像大小是错误的 . 帮我 . 也许,我不知道bind和button的命令功能(参数) . 谁通过示例代码轻松解释我...我的英语很糟糕..

from tkinter import *
from PIL import Image, ImageTk
import os
import PIL.Image

def  move_rectangular(event):
    if event.keysym == 'Up':
        canvas.move(object_1, 0, -3)
      #  canvas.move(object_2, 0, -3)
    if event.keysym == 'Down':
        canvas.move(object_1, 0, 3)
      #  canvas.move(object_2, 0, 3)   
    if event.keysym == 'Left':
        canvas.move(object_1, -3, 0)
     #   canvas.move(object_2, -3, 0)  
    if event.keysym == 'Right':
        canvas.move(object_1, 3, 0)
    #    canvas.move(object_2, 3, 0)
def  size_change(event, obj, img):    
    if event.keysym == 'b':        
        width = img.width
        height = img.height
        w = width+10
        h = height+10
        canvas.config(obj,width=w, height=h)

    if event.keysym == 's':        
        width = img.width
        height = img.height
        w = width-10
        h = height-10
        canvas.config(obj,width=w, height=h)

def size_down(obj,img):
        width = img.width
        height = img.height
        w = width-10
        h = height-10
        canvas.config(obj,width=w, height=h)
def size_up(obj,img):
        width = img.width
        height = img.height
        w = width+10
        h = height+10
        canvas.config(obj,width=w, height=h)

tk = Tk()
tk.geometry("1400x1200")
tk.title("move,resize")
mainMenu = Menu(tk)
tk.config(menu=mainMenu)


canvas = Canvas(tk, width=1300, height=853)
canvas.grid(row=0, column=2, sticky=E)

img = Image.open(os.getcwd() + '/rectangular.jpg')
photo3 = ImageTk.PhotoImage(img)
object_1 = canvas.create_image(300,220, anchor=NW, image=photo3)

canvas.bind_all('<KeyPress-Up>', move_rectangular)
canvas.bind_all('<KeyPress-Down>', move_rectangular)
canvas.bind_all('<KeyPress-Left>', move_rectangular)
canvas.bind_all('<KeyPress-Right>', move_rectangular)
# canvas bind size change
canvas.bind_all('<KeyPress-s>', lambda event, a=object_1, b=img: size_change(a, b))
canvas.bind_all('<KeyPress-b>', lambda event, a=object_1, b=img: size_change(a, b))

#button canvas size change
btn = Button(tk, text="size-", command=lambda:size_down(object_1,img))
btn.grid(row=1, column=2, sticky=N)
btn = Button(tk, text="size+", command=lambda:size_up(object_1,img))
btn.grid(row=2, column=2, sticky=N)

tk.mainloop()

_cnfmerge:回退由于:'int'对象不可迭代Tkinter回调中的异常回溯(最近一次调用最后):文件“C:\ Python34 \ lib \ tkinter__init __ . py”,第107行,在_cnfmerge中cnf.update(c )TypeError:'int'对象不可迭代在处理上述异常期间,发生了另一个异常:Traceback(最近一次调用last):文件“C:\ Python34 \ lib \ tkinter__init __ . py”,第1482行,在调用返回self中.func(* args)文件“D:/test/move,resize.py”,第70行,在btn = Button(tk,text =“size-”,command = lambda:size_down(object_1,img))文件“ D:/test/move,resize.py“,第39行,在size_down中canvas.config(obj,width = w,height = h)文件”C:\ Python34 \ lib \ tkinter__init __ . py“,第1270行,在configure中return self._configure('configure',cnf,kw)文件“C:\ Python34 \ lib \ tkinter__init __ . py”,第1254行,在_configure中cnf = _cnfmerge((cnf,kw))文件“C:\ Python34 \ lib \ t tkinter__init __ . py“,第110行,在_cnfmerge中为k,v在c.items()中:AttributeError:'int'对象没有属性'items'_cnfmerge:fa llback由于:'int'对象不可迭代Tkinter回调中的异常Traceback(最近一次调用last):文件“C:\ Python34 \ lib \ tkinter__init __ . py”,第107行,在_cnfmerge中cnf.update(c)TypeError: 'int'对象不可迭代在处理上述异常期间,发生了另一个异常:Traceback(最近一次调用last):文件“C:\ Python34 \ lib \ tkinter__init __ . py”,第1482行,在call return self.func中( * args)文件“D:/test/move,resize.py”,第72行,在btn = Button(tk,text =“size”,command = lambda:size_up(object_1,img))文件“D:/ test /move,resize.py“,第45行,在size_up中canvas.config(obj,width = w,height = h)文件”C:\ Python34 \ lib \ tkinter__init __ . py“,第1270行,在configure中返回self._configure ('configure',cnf,kw)文件“C:\ Python34 \ lib \ tkinter__init __ . py”,第1254行,在_configure中cnf = _cnfmerge((cnf,kw))文件“C:\ Python34 \ lib \ tkinter__init __ . py “,第110行,在_cnfmerge中为k,v在c.items()中:AttributeError:'int'对象没有属性'items'在Tkinter回调Tr中的异常aceback(最近调用最后一次):文件“C:\ Python34 \ lib \ tkinter__init __ . py”,第1482行,在调用return self.func(* args)文件“D:/test/move,resize.py”,行66,在canvas.bind_all('',lambda事件,a = object_1,b = img:size_change(a,b))TypeError:size_change()缺少1个必需的位置参数:'img'Tkinter回调中的异常回溯(最近最后调用):文件“C:\ Python34 \ lib \ tkinter__init __ . py”,第1482行,在调用return self.func(* args)文件“D:/test/move,resize.py”,第67行,在画布中.bind_all('',lambda事件,a = object_1,b = img:size_change(a,b))TypeError:size_change()缺少1个必需的位置参数:'img'