首页 > 解决方案 > 创建一个 python gui pdf 提取应用程序?当我设置 if 语句时,宽度函数弹出错误?

问题描述

def resize_image(img):
        width, height = int(img.size[0]), int(img.size[1])
if width > height:
            height = int(300/width*height)
            width = 300
elif height > width:
        width = int(250/height*width)
        height = 250
else:
   width, height = 250, 250
img = img.resize((width, height))
return img

(操作员出现之前的宽度错误?有人可以解决这个问题吗?)

C:\Users\DEEPA\Desktop\advancepdf>python app.py Tkinter 回调 Traceback 中的异常(最近一次调用最后一次):文件“C:\Users\DEEPA\AppData\Local\Programs\Python\Python39\lib\tkinter_ init _.py”,第 1892 行,在调用中 返回 self.func(*args) 文件“C:\Users\DEEPA\Desktop\advancepdf\app.py”,第 96 行,在 browse_btn = Button(root, textvariable=browse_text, command=lambda:open_file(), font=("Roboto",12), bg="#20bebe", fg="white", height=1, width=15) 文件 "C:\Users\DEEPA\Desktop\如果 width > height: UnboundLocalError: local variable 'width' referenced before assignment

标签: pythonuser-interfacevariablesruntime-erroroperators

解决方案


推荐阅读