You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Tkinter接鸡蛋游戏调用create_arc绘制倒弧形篮子形状异常

问题解决方法

你的篮筐形状异常是因为定义外接矩形坐标时出现了赋值笔误:
原代码中catcher_start_x2 = catcher_start_x = catcher_width这行连续赋值逻辑错误,本意是计算接篮右上角x坐标为起始x加上宽度,你误写成了把catcher_start_x也重新赋值为catcher_width,导致接篮的外接矩形x轴范围严重偏离预期,弧形自然会显示异常。

将接篮坐标定义段修改为以下内容即可:

catcher_color = "blue"
catcher_width = 100
catcher_height = 100
catcher_start_x = canvas_width / 2 - catcher_width / 2
catcher_start_y = canvas_height - catcher_width - 20
# 修正赋值错误,把等于号改为加号
catcher_start_x2 = catcher_start_x + catcher_width
catcher_start_y2 = catcher_start_y + catcher_height
catcher = c.create_arc(
    catcher_start_x,
    catcher_start_y,
    catcher_start_x2,
    catcher_start_y2,
    start=200,
    extent=140,
    style="arc",
    outline=catcher_color,
    width=30
)

修改后运行代码即可得到你预期的向上开口的倒弧形篮筐,其他功能逻辑无需调整即可正常运行。另外你初始生命值文本的字符串少了冒号,和后续更新的文本格式不统一,把text="Lives " + str(lives_remaining)改为text="Lives: " + str(lives_remaining)即可。

内容的提问来源于stack exchange,提问作者Hallows

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.06 13:18:03