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"
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'
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
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 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등을 맞추지 못했습니다.")
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)
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()
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")
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()
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
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
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
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")
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
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]
# 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)