有没有办法可以在使用海龟模块的窗口中添加按钮?
import turtle
import tkinter as tk
from time import sleep
t = turtle.Turtle()
ts = t.getscreen()
ts.register_shape("plane.gif")
t.shape("plane.gif")
t.pencolor("white")
ts.onscreenclick(t.goto)
ts.bgpic('sky.gif')
答案 0 :(得分:0)
我的朋友做了一个:
import turtle
import random
t=turtle.Pen()
def forward():
t.forward(50)
def left():
t.left(90)
def right():
t.right(90)
def red():
t.color('red')
def green():
t.color('green')
def blue():
t.color('blue')
def yellow():
t.color('yellow')
def black():
t.color('black')
def special_color():
t.color(random.random(),random.random(),random.random())
def up():
t.up()
def down():
t.down()
def circle():
t.circle(30)
#def writepi():
# t.write('π', font('Times New Roman',30,'bold'))
def circleshape():
t.shape('circle')
#def square():
# t.shape('square')
def triangle():
t.shape('triangle')
def arrow():
t.shape('arrow')
def classic():
t.shape('classic')
def turtle():
t.shape('turtle')
def layegg():
t.down()
t.begin_fill()
t.circle(4)
t.end_fill()
t.up()
def reset():
t.home()
t.clear()
from tkinter import*
tk=Tk()
forward=Button(tk,text='forward', command=forward)
forward.pack()
left=Button(tk,text='left', command=left)
left.pack()
right=Button(tk,text='right', command=right)
right.pack()
red=Button(tk,text='red', command=red)
red.pack()
green=Button(tk,text='green', command=green)
green.pack()
blue=Button(tk, text='blue', command=blue)
blue.pack()
yellow=Button(tk, text='yellow', command=yellow)
yellow.pack()
black=Button(tk, text='black', command=black)
black.pack()
specialcolor=Button(tk, text='random color', command=special_color)
specialcolor.pack()
up=Button(tk, text='up', command=up)
up.pack()
down=Button(tk, text='down', command=down)
down.pack()
circle=Button(tk, text='circle', command=circle)
circle.pack()
#pi=Button(tk, text='π', command=writepi)
#pi.pack()
cs=Button(tk, text='make it a circle', command=circleshape)
cs.pack()
#square=Button(tk, text='make it a square', command=square)
#square.pack()
triangle=Button(tk, text='make it a triangle', command=triangle)
triangle.pack()
arrow=Button(tk, text='make it an arrow', command=arrow)
arrow.pack()
clasic=Button(tk, text='back to normal', command=classic)
clasic.pack()
turtle=Button(tk, text='make it a turtle', command=turtle)
turtle.pack()
egglay=Button(tk, text='lay an egg', command=layegg)
egglay.pack()
resset=Button(tk, text'reset it all', command=reset)
resset.pack()