예제 #1
0
def main():
    root = TK.Tk()
    cv1 = TK.Canvas(root, width=300, height=200, bg='#ddffff')
    cv2 = TK.Canvas(root, width=300, height=200, bg='#ffeeee')
    cv1.pack()
    cv2.pack()
    s1 = TurtleScreen(cv1)
    s1.bgcolor(0.85, 0.85, 1)
    s2 = TurtleScreen(cv2)
    s2.bgcolor(1, 0.85, 0.85)
    p = RawTurtle(s1)
    q = RawTurtle(s2)
    p.color('red', (1, 0.85, 0.85))
    p.width(3)
    q.color('blue', (0.85, 0.85, 1))
    q.width(3)
    for t in (p, q):
        t.shape('turtle')
        t.lt(36)
    q.lt(180)
    for t in (p, q):
        t.begin_fill()
    for i in range(5):
        for t in (p, q):
            t.fd(50)
            t.lt(72)
    for t in (p, q):
        t.end_fill()
        t.lt(54)
        t.pu()
        t.bk(50)
    return 'EVENTLOOP'
예제 #2
0
def main():
    root = TK.Tk()
    cv1 = TK.Canvas(root, width=300, height=200, bg="#ddffff")
    cv2 = TK.Canvas(root, width=300, height=200, bg="#ffeeee")
    cv1.pack()
    cv2.pack()
    s1 = TurtleScreen(cv1)
    s1.bgcolor(0.85, 0.85, 1)
    s2 = TurtleScreen(cv2)
    s2.bgcolor(1, 0.85, 0.85)
    p = RawTurtle(s1)
    q = RawTurtle(s2)
    p.color("red", (1, 0.85, 0.85))
    p.width(3)
    q.color("blue", (0.85, 0.85, 1))
    q.width(3)
    for t in p,q:
        t.shape("turtle")
        t.lt(36)
    q.lt(180)
    for t in p, q:
        t.begin_fill()
    for i in range(5):
        for t in p, q:
            t.fd(50)
            t.lt(72)
    for t in p,q:
        t.end_fill()
        t.lt(54)
        t.pu()
        t.bk(50)
    return "EVENTLOOP"
예제 #3
0
파일: camina1.py 프로젝트: untxi/ada
def crea_tablero(titulo, alto, ancho):
    assert isinstance(titulo, str)
    assert isinstance(alto, int) and alto > 0
    assert isinstance(ancho, int) and ancho > 0

    ## Crea la ventana y un canvas para dibujar
    root = TK.Tk()
    root.title(titulo)
    canvas = TK.Canvas(root, width=ancho, height=alto)
    canvas.pack()

    ## Crea un TurtleScreen y la tortuga para dibujar
    global fondo_tablero
    fondo_tablero = TurtleScreen(canvas)

    ## Establece el fondo de la pizarra electrónica
    canvas["bg"] = "black"
    canvas.pack()
    global pizarra
    pizarra = RawTurtle(fondo_tablero)

    dibuja_leds()

    ## Establece las funciones para capturar las teclas
    fondo_tablero.onkeypress(lambda: detiene(), "Escape")

    por_siempre()
    fondo_tablero.listen()
    print("terminó")
    root.mainloop()
def display_help_window():
    from turtle import TK
    root = TK.Tk()
    frame = TK.Frame()
    canvas = TK.Canvas(root, width=300, height=200, bg="white")
    canvas.pack()
    help_screen = turtle.TurtleScreen(canvas)
    help_t = turtle.RawTurtle(help_screen)
    help_t.penup()
    help_t.hideturtle()
    help_t.speed('fastest')

    width, height = help_screen.screensize()
    line_height = 20
    y = height // 2 - 30
    for s in ("Click on cells to make them alive or dead.",
              "Keyboard commands:",
              " E)rase the board",
              " R)andom fill",
              " S)tep once or",
              " C)ontinuously -- use 'S' to resume stepping",
              " Q)uit"):
        help_t.setpos(-(width / 2), y)
        help_t.write(s, font=('sans-serif', 14, 'normal'))
        y -= line_height
예제 #5
0
def Rank():
    root = TK.Tk()
    cv1 = TK.Canvas(root, width=400, height=200)
    cv1.pack()
    s1 = TurtleScreen(cv1)
    s1.bgcolor("#42f4ad")
    t = RawTurtle(s1)
    t.hideturtle()
    t.penup()
    t.goto(-50,70)
    t.write("내가 예측한 1등: "+ guess)
    t.goto(-50,50)
    if PlayerNumber>=1:
        t.write("1등 : "+PlayerRank[0])
        t.goto(-50,40)
    if PlayerNumber>=2:
        t.write("2등 : "+PlayerRank[1])
        t.goto(-50,30)
    if PlayerNumber>=3:
        t.write("3등 : "+PlayerRank[2])
        t.goto(-50,20)
    if PlayerNumber>=4:
        t.write("4등 : "+PlayerRank[3])
        t.goto(-50,10)
    if PlayerNumber>=5:
        t.write("5등 : "+PlayerRank[4])
    t.goto(-100,-20)
    if(guess==PlayerRank[0]):
        t.write("축하드립니다. 1등을 맞추셨습니다.")
    else:
        t.write("1등을 맞추지 못했습니다.")
예제 #6
0
def yardým_penceresini_göster():
    from turtle import TK # Sýnýf ithali...
    #kök = TK.Tk() # Metod çaðýrmalý nesne...
    #çerçeve = TK.Frame()
    tuval = TK.Canvas (TK.Tk(), width=400, height=200, bg="WHITE") # Yardým ekran büyüklüðü...
    tuval.pack()

    yardým_ekraný = turtle.TurtleScreen (tuval)
    en, boy = yardým_ekraný.screensize() 

    yardým_penceresi = turtle.RawTurtle (yardým_ekraný)
    yardým_penceresi.penup()
    yardým_penceresi.hideturtle()
    yardým_penceresi.speed ('fastest')

    satýr_boyu = 20
    y = boy / 2 - 30
    for satýr in ("Fareyle týklanan hücre canlanýr veya ölür.",
            "Pano odaklýyken klavye komutlarý:", " ",
            " S)il panoyu tamamen",
            " G)eliþigüzel pano dolacak",
            " T)ek tek adýmlarla ilerlenir",
            " D)evamlý ilerlenir -- T ile tek teke dönebilirsin", " ",
            " K)apat pencereleri ve çýk"):
        yardým_penceresi.setpos (- en / 2, y)
        yardým_penceresi.write (satýr, font = ('sans-serif', 14, 'normal'))
        y -= satýr_boyu
def newwindow(title=None, size=(200, 200), pos=(100, 100)):
    wn = TK.Tk()
    wn.geometry(sizetostr(size, pos))
    if title == None:
        title = rander()
    wn.title(title)
    cv = TK.Canvas(wn, width=size[0], height=size[1])
    cv.pack()
    sc = turtle.TurtleScreen(cv)
    return (wn, cv, sc)
예제 #8
0
def crea_tablero(titulo, alto, ancho):
    """ Crea una pizarra electronica

        Entradas:
            titulo : titulo de la ventana que contendra la pizarra electronica
            alto   : alto de la ventana en pixeles
            ancho  : ancho de la ventna en pixeles
            
        Salidas: Ninguna
        
        Restricciones: titulo es una tira, alto y ancho son enteros positivos
    """

    ## Restricciones
    assert isinstance(titulo, str)
    assert isinstance(alto, int) and alto > 0
    assert isinstance(ancho, int) and ancho > 0

    ## Crea la ventana y un canvas para dibujar
    root = TK.Tk()
    root.title(titulo)
    canvas = TK.Canvas(root, width=ancho, height=alto)
    canvas.pack()

    ## Crea un TurtleScreen y la tortuga para dibujar
    fondo_tablero = TurtleScreen(canvas)

    ## Establece el fondo de la pizarra electronica
    canvas["bg"] = "black"
    canvas.pack()
    pizarra = RawTurtle(fondo_tablero)
    dibuja_leds(pizarra)

    ## Establece las funciones para capturar las teclas
    fondo_tablero.onkeypress(lambda: envie_0(pizarra), "0")
    fondo_tablero.onkeypress(lambda: envie_1(pizarra), "1")
    fondo_tablero.onkeypress(lambda: envie_2(pizarra), "2")
    fondo_tablero.onkeypress(lambda: envie_3(pizarra), "3")
    fondo_tablero.onkeypress(lambda: envie_4(pizarra), "4")
    fondo_tablero.onkeypress(lambda: envie_5(pizarra), "5")
    fondo_tablero.onkeypress(lambda: envie_6(pizarra), "6")
    fondo_tablero.onkeypress(lambda: envie_7(pizarra), "7")
    fondo_tablero.onkeypress(lambda: envie_8(pizarra), "8")
    fondo_tablero.onkeypress(lambda: envie_9(pizarra), "9")
    fondo_tablero.onkeypress(lambda: dibuja_leds(pizarra), "Escape")
    fondo_tablero.listen()

    root.mainloop()
예제 #9
0
 def init_screen(self):
     # intialise screen and turn off auto-render
     root = Tk()
     root.wm_title(self.window_title)
     window = TK.Canvas(master=root, width=self.width, height=self.height)
     window.pack()
     self.screen = TurtleScreen(window)
     self.screen.tracer(0, 0)
    def __init__(self, titulo, alto, ancho):

        assert isinstance(titulo, str)
        assert isinstance(alto, int) and alto > 0
        assert isinstance(ancho, int) and ancho > 0

        self.root = TK.Tk()
        self.root.title(titulo)
        self.canvas = TK.Canvas(self.root, width=ancho, height=alto)
        self.canvas.pack()

        self.fondo_ventana = TurtleScreen(self.canvas)
        self.fondo_ventana.setworldcoordinates(0, alto, ancho, 0)

        self.canvas["bg"] = "gold"
        self.canvas.pack()

        self.pencil = RawTurtle(self.fondo_ventana)
        self.pencil.pencolor("white")
예제 #11
0
def crea_tablero(titulo, alto, ancho):
    """ Crea una pizarra electrónica.
        Entradas:
            titulo : título de la ventana que contendrá la
                     pizarra electrónica.
            alto   : alto de la ventana en pixeles.
            ancho  : ancho de la ventna en pixeles.
        Salidas:
            Ninguna.
        Restricciones:
            titulo es una tira, alto y ancho son enteros positivos.
    """
    assert isinstance(titulo, str)
    assert isinstance(alto, int) and alto > 0
    assert isinstance(ancho, int) and ancho > 0

    ## Crea la ventana y un canvas para dibujar
    root = TK.Tk()
    root.title(titulo)
    canvas = TK.Canvas(root, width=ancho, height=alto)
    canvas.pack()

    ## Crea un TurtleScreen y la tortuga para dibujar
    global fondo_tablero
    fondo_tablero = TurtleScreen(canvas)

    ## Establece el fondo de la pizarra electrónica
    canvas["bg"] = "black"
    canvas.pack()
    global pizarra
    pizarra = RawTurtle(fondo_tablero)

    dibuja_leds()

    ## Establece las funciones para capturar las teclas
    fondo_tablero.onkeypress(lambda: detiene(), "Escape")

    por_siempre()
    fondo_tablero.listen()
    print("terminó")
    root.mainloop()
예제 #12
0
def display_help_window():
    from turtle import TK
    root = TK.Tk()
    frame = TK.Frame()
    canvas = TK.Canvas(root, width=200, height=250, bg="grey")
    canvas.pack()
    help_screen = turtle.TurtleScreen(canvas)
    help_t = turtle.RawTurtle(help_screen)
    help_t.penup()
    help_t.hideturtle()
    help_t.speed('fastest')

    width, height = help_screen.screensize()
    line_height = 20
    y = height // 2 - 30
    for s in ("Clique nas celulas para definir se estao vivas ou mortas",
              "Comandos do teclado:", " A)Apaga o quadro", " U)Uma geracao",
              " C)Geracao continua", " S)Sair"):
        help_t.setpos(-(width / 2), y)
        help_t.write(s, font=('sans-serif', 14, 'normal'))
        y -= line_height
예제 #13
0
    def display_help_window(self):
        from turtle import TK
        root = TK.Tk()
        frame = TK.Frame()
        canvas = TK.Canvas(root, width=300, height=200, bg="white")
        canvas.pack()
        help_screen = turtle.TurtleScreen(canvas)
        help_t = turtle.RawTurtle(help_screen)
        help_t.penup()
        help_t.hideturtle()
        help_t.speed('fastest')

        width, height = help_screen.screensize()
        line_height = 20
        y = height // 2 - 30
        for s in ("Click on cells to make them alive or dead.",
                  "Key commands:", " E- Erase ", " R- Random ",
                  " P- Upload Pic ", " S- Step ", " C- Loop ", " Q- Quit "):
            help_t.setpos(-(width / 2), y)
            help_t.write(s, font=('sans-serif', 14, 'normal'))
            y -= line_height
예제 #14
0
def telaAjudaDisplay():
    from turtle import TK
    raiz = TK.Tk()
    frame = TK.Frame()
    quadro = TK.Canvas(raiz, width=200, height=250, bg="grey")
    quadro.pack()
    telaAjuda = turtle.TurtleScreen(quadro)
    ajudaT = turtle.RawTurtle(telaAjuda)
    ajudaT.penup()
    ajudaT.hideturtle()
    ajudaT.speed('fastest')

    largura, altura = telaAjuda.screensize()
    alturaLinha = 20
    y = altura // 2 - 30
    for s in ("Clique nas celulas para definir se estao vivas ou mortas",
              "Comandos do teclado:", " A)Apaga o quadro", " U)Uma geracao",
              " C)Geracao continua", " P)Pausar Geracao Continua", " S)Sair"):
        ajudaT.setpos(-(largura / 2), y)
        ajudaT.write(s, font=('sans-serif', 14, 'normal'))
        y -= alturaLinha
예제 #15
0
    def __init__(self, titulo, alto, ancho):
        
        assert isinstance(titulo, str)
        assert isinstance(alto, int) and alto > 0
        assert isinstance(ancho, int) and ancho > 0
 
        ## Crea la ventana y un canvas para dibujar
        self.root = TK.Tk()
        self.root.title(titulo)
        self.canvas = TK.Canvas(self.root, width=ancho, height=alto)
        self.canvas.pack()
         
        ## Crea un TurtleScreen y la tortuga para dibujar
        self.fondo_ventana = TurtleScreen(self.canvas)
        self.fondo_ventana.setworldcoordinates(0, alto, ancho, 0)
 
        ## Establece el color de fondo
        self.canvas["bg"] = "blue"
        self.canvas.pack()
 
        ## Crea una tortuga para dibujar
        self.pencil = RawTurtle(self.fondo_ventana)
        self.pencil.pencolor("white")
예제 #16
0
def display_help_window():
    from turtle import TK
    root = TK.Tk()
    frame = TK.Frame()
    canvas = TK.Canvas(root, width=350, height=150, bg="white")
    canvas.pack()
    help_screen = turtle.TurtleScreen(canvas)
    help_t = turtle.RawTurtle(help_screen)
    help_t.penup()
    help_t.hideturtle()
    help_t.speed('fastest')

    width, height = help_screen.screensize()
    line_height = 20
    y = height // 2 - 30
    for s in ("Con un click las cambias entre vivas y muertas",
              " E es para borrar todo",
              " R es para llenarlo aleatoriamente",
              " S es para siguiente generacion",
              " C es para dar generaciones continuas",
              " Q para salir"):
        help_t.setpos(-(width / 2), y)
        help_t.write(s, font=('arial', 12, 'normal'))
        y -= line_height
예제 #17
0
파일: world.py 프로젝트: ejs/turtlepower
    def __init__(self, width, height, borders=wrap):
        self.width = width
        self.half_width = width // 2
        self.height = height
        self.half_height = height // 2
        self.borders = borders

        # intialise screen and turn off auto-render
        window = TK.Canvas(width=width, height=height)
        window.pack()
        self.screen = TurtleScreen(window)
        self.screen.tracer(0, 0)
        self.fps = 0
        self.done = True
        self.turtles = []
        self.update_freq = 1000  #int(1 / 30.0 * 1000)
from turtle import TK

root = TK.Tk()
canvas = TK.Canvas(root, width=500, bg="#ddffff")
canvas.pack()
canvas.create_text(200,
                   250,
                   fill="darkblue",
                   font="Times 20",
                   text="hello world")

TK.mainloop()
예제 #19
0
파일: basicoTurtle.py 프로젝트: untxi/ada

def getInput():
    return screen.textinput(
        "Figura", " 1. Rectangle\n 2. Square\n 3. Triangle\
    \n 4. House\n 5. Doole\n 6. Pattern 1\n 7. Pattern 2\n 8. Circle\n 9. Petal\
    \n10.Flower\n11.Shape Change\n 0. Exit or <Enter>")


def param(default, n):
    return default if len(ops) == 1 in range(1, n + 1) else ops[n]


from turtle import TurtleScreen, RawTurtle, TK

root = TK.Tk()
root.title("cambio de tamaño")
canvas = TK.Canvas(root, width=1000, height=1000, bg="white")
canvas.pack()
screen = TurtleScreen(canvas)
turtle = RawTurtle(screen)

turtle.shape("turtle")
turtle.speed(5)
while True:
    x = getInput()
    if x in ["", "0", "00"] or x == None:
        break
    turtle.reset()
    ops = [int(y) for y in x.split()]
    x = ops[0]
예제 #20
0
from turtle import TurtleScreen, RawTurtle, TK
root = TK.Tk()
cv1 = TK.Canvas(root, width=500, height=500, bg="#ddffff")
cv1.pack()
s1 = TurtleScreen(cv1)
s1.bgcolor("orange")
p = RawTurtle(s1)
t = RawTurtle(s1)

p.begin_fill()
p.circle(60)
p.end_fill()

TK.mainloop()
예제 #21
0
#!/usr/bin/env python3
## DEMONSTRATES USE OF 2 CANVASES, SO CANNOT BE RUN IN DEMOVIEWER!
"""turtle example: Using TurtleScreen and RawTurtle
for drawing on two distinct canvases.
"""
from turtle import TurtleScreen, RawTurtle, TK

root = TK.Tk()
cv1 = TK.Canvas(root, width=300, height=200, bg="#ddffff")
cv2 = TK.Canvas(root, width=300, height=200, bg="#ffeeee")
cv1.pack()
cv2.pack()

s1 = TurtleScreen(cv1)
s1.bgcolor(0.85, 0.85, 1)
s2 = TurtleScreen(cv2)
s2.bgcolor(1, 0.85, 0.85)

p = RawTurtle(s1)
q = RawTurtle(s2)

p.color("red", (1, 0.85, 0.85))
p.width(3)
q.color("blue", (0.85, 0.85, 1))
q.width(3)

for t in p, q:
    t.shape("turtle")
    t.lt(36)

q.lt(180)
예제 #22
0
    s1.bgcolor(0.85, 0.85, 1)
    s2 = TurtleScreen(cv2)
    s2.bgcolor(1, 0.85, 0.85)
    p = RawTurtle(s1)
    q = RawTurtle(s2)
    p.color('red', (1, 0.85, 0.85))
    p.width(3)
    q.color('blue', (0.85, 0.85, 1))
    q.width(3)
    for t in (p, q):
        t.shape('turtle')
        t.lt(36)
    q.lt(180)
    for t in (p, q):
        t.begin_fill()
    for i in range(5):
        for t in (p, q):
            t.fd(50)
            t.lt(72)
    for t in (p, q):
        t.end_fill()
        t.lt(54)
        t.pu()
        t.bk(50)
    return 'EVENTLOOP'


if __name__ == '__main__':
    main()
    TK.mainloop()
예제 #23
0
    p.color("red", (1, 0.85, 0.85))
    p.width(3)
    q.color("blue", (0.85, 0.85, 1))
    q.width(3)

    for t in p, q:
        t.shape("turtle")
        t.lt(36)

    q.lt(180)

    for t in p, q:
        t.begin_fill()
    for i in range(5):
        for t in p, q:
            t.fd(50)
            t.lt(72)
    for t in p, q:
        t.end_fill()
        t.lt(54)
        t.pu()
        t.bk(50)

    return "EVENTLOOP"


if __name__ == '__main__':
    main()
    TK.mainloop()  # keep window open until user closes it
예제 #24
0
    p.color("red", (1, 0.85, 0.85))
    p.width(3)
    q.color("blue", (0.85, 0.85, 1))
    q.width(3)

    for t in p,q:
        t.shape("turtle")
        t.lt(36)

    q.lt(180)

    for t in p, q:
        t.begin_fill()
    for i in range(5):
        for t in p, q:
            t.fd(50)
            t.lt(72)
    for t in p,q:
        t.end_fill()
        t.lt(54)
        t.pu()
        t.bk(50)

    return "EVENTLOOP"


if __name__ == '__main__':
    main()
    TK.mainloop()  # keep window open until user closes it
p.width(3)
q.color("blue", (0.85, 0.85, 1))
q.width(3)

for t in p,q:
    t.shape("turtle")
    t.lt(36)

q.lt(180)

for t in p, q:
    t.begin_fill()
for i in range(5):
    for t in p, q:
        t.fd(50)
        t.lt(72)
for t in p,q:
    t.end_fill()
    t.lt(54)
    t.pu()
    t.bk(50)

## Want to get some info?

print(s1, s2)
print(p, q)
print(s1.turtles())
print(s2.turtles())

TK.mainloop()
예제 #26
0
파일: flocking.py 프로젝트: ejs/turtlepower
    elif x < -W / 2:
        nx = -W / 2

    if y > H / 2:
        ny = H / 2
    elif y < -H / 2:
        ny = -H / 2

    if nx is not None:
        t.setx(nx)
    if ny is not None:
        t.sety(ny)


# intialise screen and turn off auto-render
window = TK.Canvas(width=W, height=H)
window.pack()

#from turgles import TurgleScreenBase
#TurtleScreen.__bases__ = (TurgleScreenBase,)
#window = pyglet.window.Window(width=W, height=H)

s = TurtleScreen(window)
s.tracer(0, 0)

# random initial positions
turtles = [RawTurtle(s) for i in range(n)]
for t in turtles:
    t.ht()
    t.penup()
    t.goto(randint(0, W) - W / 2, randint(0, H) - H / 2)
예제 #27
0
def get_screen(w, h):
    cv = TK.Canvas(width=w, height=h)
    cv.pack()
    return TurtleScreen(cv)
예제 #28
0
 def closeWindow(self):
     TK._exit(0)
예제 #29
0
from turtle import TurtleScreen, RawTurtle, TK

root = TK.Tk()
root.title("Ejemplo 1")
canvas = TK.Canvas(root, width=500, height=500)
canvas.pack()

turtle = RawTurtle(screen)

turtle.shape("turtle")

turtle.left(20)

turtle.forward(50)
turtle.left(90)
turtle.forward(50)
turtle.left(90)
turtle.forward(50)
turtle.left(90)
turtle.forward(50)
turtle.left(90)
delay(1000)
turtle.left(30)

turtle.forward(50)
turtle.left(90)
turtle.forward(50)
turtle.left(90)
turtle.forward(50)
turtle.left(90)
turtle.forward(50)
예제 #30
0
# third-party modules, followed by any changes to the path and your own modules
import math
from turtle import TurtleScreen, RawTurtle, TK

# Metadata
__author__ = "Mark Demore"
__email__ = "*****@*****.**"
__date__ = "Aug 25, 2016"

# Constants
CANVAS_WIDTH = 600
CANVAS_HEIGHT = int(CANVAS_WIDTH * 9 /
                    16)  # Produces the eye-pleasing 16:9 HD aspect ratio.

# Create a Tkinter graphics window
graphics_window = TK.Tk()
graphics_window.title("Lab 5 Problems")

# Create a "canvas" inside the graphics window to draw on
my_canvas = TK.Canvas(graphics_window,
                      width=CANVAS_WIDTH,
                      height=CANVAS_HEIGHT)
my_canvas.pack()  # Organizes my_canvas inside the graphics window

# Create a "canvas" made specifically for turtle graphics
turtle_canvas = TurtleScreen(my_canvas)
turtle_canvas.bgcolor("white")

# Create a turtle to draw on the canvas
mary = RawTurtle(turtle_canvas)