2014-04-28 63 views
0

有沒有一種方法可以將按鈕添加到使用龜模塊的窗口?Python的龜模塊

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

您可以任意按鈕添加到一個窗口?按鈕與龜有關時是否有任何具體問題?你遇到什麼類型的問題,它沒有顯示,沒有工作或者有什麼不同? –

+0

沒有問題我只是想爲用戶添加一個按鈕來退出程序,或者在此之後進入下一個窗口。 – user3565867

回答

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