简体   繁体   English

Python的Turtle模块

[英]Turtle Module for Python

Is there a way you can add buttons to a window that's using the turtle module? 有没有一种方法可以向使用turtle模块的窗口添加按钮?

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')

My friend made one that goes: 我的朋友提出了一个建议:

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()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM