python中的turtle模块如何建立画布大小_将turtle模块与tkinter画布集成

import turtle

import tkinter as tk

def forward():

t.forward(100)

def back():

t.back(100)

def left():

t.left(90)

def right():

t.right(90)

root = tk.Tk()

canvas = tk.Canvas(master = root, width = 500, height = 500)

canvas.pack()

t = turtle.RawTurtle(canvas)

t.pencolor("#ff0000") # Red

t.penup() # Regarding one of the comments

t.pendown() # Regarding one of the comments

tk.Button(master = root, text = "Forward", command = forward).pack(side = tk.LEFT)

tk.Button(master = root, text = "Back", command = back).pack(side = tk.LEFT)

tk.Button(master = root, text = "Left", command = left).pack(side = tk.LEFT)

tk.Button(master = root, text = "Right", command = right).pack(side = tk.LEFT)

root.mainloop()

我以前从未使用过这个模块,但我写的东西似乎可以满足您的要求

参考资料

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值