コード例 #1
0
ファイル: In Memoriam.py プロジェクト: CSA-JDM/In-Memoriam
    def __init__(self):
        # Root Initialization
        self.root = turtle._Root()
        self.root.config(width=1280, height=720)
        self.root.bind("<Escape>", lambda args: self.root.destroy())
        self.root.title("In Memoriam")

        # Canvas Initialization
        self.canvas = turtle.Canvas(self.root)
        self.canvas.config(width=1280, height=720, background="white")
        self.canvas.place(x=0, y=0)

        # Audio Initialization
        sayo_nara = Audio(self.root, r"..\Final-Project\Music\Sayo-nara.mp3")
        sayo_nara.play(loop=True)

        # Item Dictionaries
        self.buttons = {}
        self.text_boxes = {}
        self.text_inputs = {}

        # Time Text Box Initialization
        current_time = time.localtime()
        self.text_boxes["time_text_box"] = Canvas_Objects.TextBox(
            self.canvas, x=1140, y=650, length=140, height=65,
            text=f"  {current_time[3]}:{current_time[4]}:{current_time[5]}\n"
                 f"{current_time[1]}/{current_time[2]}/{current_time[0]}"
        )

        # Main Sequence
        self.menu()
        self.time_update()
        self.root.mainloop()
コード例 #2
0
def adapter():
    # aloue la taille dispo a la tortue
    R.xFen = calc.winfo_width() - f_clavier.winfo_width() - 30
    R.yFen = calc.winfo_height() - l_mode.winfo_height() - 30

    R.actualiser()
    fenTortue.destroy()
    global fenTortue
    global ecran
    global t
    fenTortue = turtle.Canvas(f_turtle, height=R.yFen, width=R.xFen)
    fenTortue.pack(padx=10, pady=10)
    ecran = turtle.TurtleScreen(fenTortue)
    t = turtle.RawTurtle(ecran)
    R.actualiser()
    t.ht()
コード例 #3
0
    def build(self):

        self.canvas = turtle.Canvas(self.root)
        self.canvas.grid(row=0, rowspan=10, column=0)  #side=LEFT)
        self.canvas.config(width=self.size[0], height=self.size[1])
        self.screen = turtle.TurtleScreen(self.canvas)

        self.builder = turtle.RawTurtle(self.canvas)
        self.builder.speed(0)
        self.builder.ht()
        self.builder.getscreen().tracer(0)
        #Colour #Box Colour #Box Layout #Path Width.
        self.Warehouse = Area(self, self.f_ratio, "red", "LightSalmon3",
                              self.strg_layout, 0.4)
        self.Warehouse.draw()
        self.Bay = Area(self, 1 - self.f_ratio, "purple", "LightSalmon3",
                        self.bay_layout, 0.4)
        self.Bay.draw()

        self.builder.getscreen().update()
        self.builder.getscreen().tracer(1, 0)
コード例 #4
0
 def __init__(self):
     self.cv = turtle.Canvas(width=128, height=128)
     self.width = 128
     self.height = 128
コード例 #5
0
import turtle
import time
from ball import Ball

J = turtle.Canvas()
SCREEN_WIDTH = J.winfo_width() / 2
SCREEN_HEIGHT = J.winfo_height() / 2
mouse = Ball(0, 0, 0, 0, 10, "blue")


def inst():

    inn = turtle.clone()
    inn.home()
    turtle.clear()
    turtle.addshape("in.gif")
    inn.shape("in.gif")
    inn.stamp()
    turtle.update()


def play():
    turtle.clear()
    turtle.update()


ans = True
turtle.ht()
turtle.tracer(0)
turtle.penup()
turtle.goto(-100, -100)
コード例 #6
0
#Sample 1


import turtle

#User selected turtle graphics
canvas=turtle.Canvas()
tobi=turtle.Turtle()
'''
print("What shape do you want the turtle to have?\n1. turtle\n2. triangle\n3. classic")
shape = input('Your answer is: ')

if shape == '1' or shape == 'turtle':
    shape = 'turtle'
elif shape == '2' or shape == 'triangle':
    shape = 'triangle'
elif shape == '3' or shape == 'classic':
    shape = 'classic'
else:
    print("incorrect answer, setting the turtle's shape to circle")
    shape = 'circle'

tobi.shape(shape)

print("What color do you want the turtle to have?\n1. red\n2. green\n3. blue\n4. orange")
color = input('Your answer is: ')

if color == '1' or color == 'red':
    color = 'red'
elif color == '2' or color == 'green':
    color = 'green'
コード例 #7
0
ファイル: Spirals.py プロジェクト: lilkeet/spirals
    else:
        root.geometry("240x125")
        advanced_tab = False
        
#to restart program
def restart():
    os.execl(sys.executable, sys.executable, *sys.argv)
    
#Tkinter Windows    
root = tk.Tk()

top = tk.Toplevel(root)


#Secondary window, the turtle canvas
canvas = turtle.Canvas(top)
canvas.pack(fill="both",expand=1)
t = turtle.RawTurtle(canvas)
turtle.TurtleScreen(canvas).bgcolor("black")
t.speed(0)
t.up()

tk.Label(
    root,
    text="How long to run:\n(In seconds)"
    ).grid(row=0,column=0,rowspan=2)

end = tk.Entry(root,width=10)
end.grid(row=0,column=1)

tk.Label(
コード例 #8
0
def mainprogram():
    Turtle.Screen().setworldcoordinates(-400, -400, 400, 400)
    centipede(14, 10, 200)
    t.Canvas().exitonclick()
コード例 #9
0
f_clavier.pack(side="bottom")
f_turtle.pack(side="right")

# déclaration et affichage du label modedans le label tortue
mode = "Calculatrice"
l_mode = Label(f_turtle, text=mode, bg="grey", fg="white")
l_mode.pack()

# déclaratior et affichage de l'entrée et du label entée
lf_expression = LabelFrame(f_commande, text="entrée", bg="white")
lf_expression.pack(padx=2, pady=2)
l_expression = Label(lf_expression, text="", bg="white")
l_expression.pack(padx=2, pady=2)

# déclaration et affichage de la tortue
fenTortue = turtle.Canvas(f_turtle, height=R.yFen, width=R.xFen)
fenTortue.pack(padx=10, pady=10)
ecran = turtle.TurtleScreen(fenTortue)
t = turtle.RawTurtle(ecran)
t.ht()

# affichage des boutons
for i in range(len(boutons)):
    for j in range(len(boutons[i])):
        try:
            Button(f_clavier,
                   text=boutons[i][j][0],
                   relief="flat",
                   command=boutons[i][j][1],
                   height=1,
                   width=4).grid(
コード例 #10
0
def start(width, height, lastMaze, speed, algo):

    maze_color = 'white'
    bg_color = 'black'

    def setupMaze(grid):
        for y in range(
                len(grid)):  # loop through all the elements in the list(maze)
            for x in range(len(grid[y])):
                character = grid[y][x]
                screen_x = -588 + (x * cellWidth
                                   )  # calculate the position of x coordinate
                screen_y = 288 - (y * cellWidth
                                  )  # calculate the position of y coordinate

                if character == "+":  # if wall
                    maze.goto(screen_x, screen_y)  # go to location
                    maze.stamp()  # put stamp (make wall)
                    walls.append((screen_x, screen_y))  # append in walls list

                elif character == "e":  # if end point (target/goal)
                    maze.goto(screen_x, screen_y)  # goto location
                    maze.color('green')  # make color green
                    maze.stamp()  # put stamp
                    maze.color(maze_color)  # switch back to wall color
                    finish.append(
                        (screen_x, screen_y))  # append in finish list

    grid = maze_generator.createMaze(
        width, height, lastMaze)  # generate a maze with given width and height
    cellWidth = row = int(
        min(700.0 / (len(grid) * 1.1), 1300.0 / (len(grid[0]) * 1.05))
    )  # calculate the width of each cell to fit the maze properly on screen

    window = tk.Tk()  # create a tkinter window
    window.title("Maze-Solver")  # put title
    window.geometry('1300x700')  # set dimension
    window.resizable(False, False)  # make it non resizeable
    wn = turtle.Canvas(window, width=1300, height=700)  # take turtle canvas
    wn.place(x=0, y=0)  # pin the canvas on the window

    maze = turtle.RawTurtle(wn)  # create a turtle object for maze
    wn['bg'] = bg_color  # set background color
    maze.shape('square')  # set shape of wall as sqaure
    maze.penup()  # put penup (no trail)
    maze.color(maze_color)  # set wall color
    maze.speed(0)  # fastest									# set speed to draw maze as fastest(0)
    maze.shapesize(cellWidth / 24.0)  # set the size of each cell
    maze.hideturtle()  # hide the maze turtle

    walls = []  # list to store walls
    finish = []  # list to store the end point
    setupMaze(grid)  # create the maze
    maze.speed(speed)  # set the speed given by the user
    maze.hideturtle()  # hide

    myTurtle = turtle.RawTurtle(wn)  # create a turtle object for mover(solver)
    myTurtle.shape('turtle')  # set its shape
    myTurtle.hideturtle()  # hide the turtle
    myTurtle.color('red')  # set its color as red
    myTurtle.speed(0)  # set its speed to fastest(0)
    myTurtle.penup()  # put pen up initially (no trail)
    myTurtle.shapesize(cellWidth / 24.0)  # set the size of each cell
    myTurtle.goto(-588 + cellWidth,
                  288 - cellWidth)  # move the turtle to the starting position
    myTurtle.speed(speed)  # set the speed to user given speed
    myTurtle.pendown()  # put the pen down (for trail)

    # call apt function as per the given algo
    if (algo == 'Left Hand Rule'):
        LHR.start(myTurtle, walls, finish, cellWidth)
    elif (algo == 'Right Hand Rule'):
        RHR.start(myTurtle, walls, finish, cellWidth)
    elif (algo == 'Random Mouse'):
        randomMouse.start(myTurtle, walls, finish, cellWidth)
    elif (algo == 'Depth First Search - 1'):
        dfs1.start(myTurtle, walls, finish, cellWidth)
    elif (algo == 'Depth First Search - 2'):
        dfs2.start(myTurtle, walls, finish, cellWidth, maze)
    elif (algo == 'Breadth First Search'):
        bfs.start(myTurtle, walls, finish, cellWidth, maze)
    elif (algo == 'Dead-End Filling'):
        deadendFilling.start(myTurtle, walls, finish, cellWidth, maze)
    elif (algo == 'A* Search'):
        aStar.start(myTurtle, walls, finish, cellWidth, maze)
    window.mainloop()  # prevents program from quiting


# start(10,10,False,5,'A* Search') # used for faster debugging
コード例 #11
0
    def draw(self,
             master,
             colors,
             row=0,
             column=0,
             width=1440,
             height=800,
             size=3):

        global defaultScreenSize, window, canvasPosition, speed, canvas

        window = tk.Frame(width=width,
                          height=height,
                          relief=tk.RAISED,
                          borderwidth=3)
        #        window.grid(row = row, column = column)
        window.pack()
        #        window.geometry("1440x800")
        #        window.resizable(True, True)
        speed = 16

        canvas = turtle.Canvas(window, width=4096, height=2048)
        canvasPosition = [0, height / 2 - 1024]
        move(0, 0)

        t = turtle.RawTurtle(canvas)
        t.speed(0)

        master.bind("<KeyPress-Up>", down)
        master.bind("<KeyPress-Down>", up)
        master.bind("<KeyPress-Right>", right)
        master.bind("<KeyPress-Left>", left)
        master.bind("<KeyPress-p>", printCenter)
        master.bind("<KeyPress-r>", resetPosition)

        print(self.branches)

        t.hideturtle()
        if (size == 1):
            drawBranch(t,
                       self.branches[0],
                       -2048,
                       0,
                       16,
                       32,
                       1,
                       deepestLevel(self.branches) - 2,
                       colors=colors)
        elif (size == 2):
            drawBranch(t,
                       self.branches[0],
                       -2048,
                       0,
                       24,
                       64,
                       1,
                       deepestLevel(self.branches) - 2,
                       colors=colors)
        else:
            drawBranch(t,
                       self.branches[0],
                       -2048,
                       0,
                       32,
                       64,
                       2,
                       deepestLevel(self.branches) - 2,
                       colors=colors)
コード例 #12
0
ファイル: tk_turtle.py プロジェクト: luolugithub/circle_draw
# -*- coding: utf-8 -*-
# @Time    : 2020/7/25 下午4:52
# @Author  : Luo Lu
# @Email   : [email protected]
# @File    : tk_turtle.py
# @Software: PyCharm

import tkinter as tk
import turtle

root = tk.Tk()
canvas = turtle.Canvas(root, width=2000, height=2000)
# canvas = turtle.ScrolledCanvas(root)
canvas.pack(side=tk.LEFT)

screen = turtle.TurtleScreen(canvas)

# screen.setworldcoordinates(0, 0, 2000, 2000)

turtle = turtle.RawTurtle(screen)
turtle.goto(0, 0)

screen.mainloop()