tkinter - tkinter 画布矩形使用项目配置调整大小
问题描述
我有一个画布并绘制了一个矩形,稍后我想根据变化的数据调整它的大小。
rect = canvas.create_rectangle(10, 130, 80, 20)
对于颜色,看起来有一个“填充”属性,但不确定我们如何更改坐标,尤其是高度。
canvas.itemconfigure(rect, fill="#000000", ...want to change height...)
能否请你帮忙
解决方案
您可以使用canvas.coords(...)
来调整矩形的大小:
def resize_rect(dy):
# get the current geometry of rectangle
coords = canvas.coords(rect)
# update its height by modifying the last value of coords
coords[-1] += dy
# update the rectangle
canvas.coords(rect, coords)
推荐阅读
- android - android showing multiple launch icon after installed
- php - Separate a long string of Dates and Times
- python - 我不明白我的 on_member_join/on_member_remove 函数遇到的这些错误
- android - write an android gui chess interface without ndk
- fonts - Flutter:单个字符和自定义字体的问题
- java - 缓冲图像正在生成空图像
- python - How do you fix a FileNotFound error code even though the directory does exist on the drive?
- swift - 为什么我的模型没有在视图控制器中显示它的成员?
- chef-infra - Chef - 读取 chef recipe.rb 文件中的外部属性
- reactjs - 反应:不断收到错误:尝试将字符串作为道具传递时`未终止的字符串常量`