python - 创建一个 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
解决方案
推荐阅读
- azure - 使用 Azure RUN 命令的 Get-Service 命令脚本响应未显示 Azure 虚拟机的所有列值
- javascript - TypeError:无法读取未定义的属性“地图”错误
- android - 如何在 Webview Flutter 中自定义错误页面
- r - 如何获得有关“如果两次使用相同的输出,闪亮的应用程序将无法工作”的警告
- angular - 未捕获的 TypeError:Angular / 依赖项更新后将循环结构转换为 JSON
- firebase - Firebase Cloud Function + Firestore 性能问题
- c++ - 如何获取目录的属性,例如上次访问和上次修改
- javascript - 过滤特定对象的对象数组(Javascript)
- java - dateChooser 设置今天的日期
- django - Django mptt - 如何显示全名