gpt4 book ai didi

python - 如何将 turtle 移动到 Canvas 的边缘?

转载 作者:行者123 更新时间:2023-12-01 05:56:08 26 4
gpt4 key购买 nike

有没有办法让光标( turtle )移动到 Canvas 的右、左、下、上边缘?

Someone suggested使用 turtle.setx() 并将参数设置为 0 移动到最左边的位置。但是当我这样做时, turtle 会移动到默认位置(到中心)

最佳答案

使用window_width()window_height()函数确定窗口的大小:

这会将 turtle 移动到最右边缘:

import turtle as tt

def main():
tt.reset()
print(tt.window_width(), tt.window_height())
tt.setx(tt.window_width()//2)

if __name__ == '__main__':
main()
tt.mainloop()

关于python - 如何将 turtle 移动到 Canvas 的边缘?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12534473/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com