Esempio n. 1
0
def ex59():
    canvas = Canvas(width=300, height=300, bg='green')
    canvas.pack(expand=YES, fill=BOTH)
    x0 = 150
    y0 = 100
    canvas.create_oval(x0 - 10, y0 - 10, x0 + 10, y0 + 10)
    canvas.create_oval(x0 - 20, y0 - 20, x0 + 20, y0 + 20)
    canvas.create_oval(x0 - 50, y0 - 50, x0 + 50, y0 + 50)
    B = 0.809
    for i in range(16):
        a = 2 * math.pi / 16 * i
        x = math.ceil(x0 + 48 * math.cos(a))
        y = math.ceil(y0 + 48 * math.sin(a) * B)
        canvas.create_line(x0, y0, x, y, fill='red')
    canvas.create_oval(x0 - 60, y0 - 60, x0 + 60, y0 + 60)

    for k in range(501):
        for i in range(17):
            a = (2 * math.pi / 16) * i + (2 * math.pi / 180) * k
            x = math.ceil(x0 + 48 * math.cos(a))
            y = math.ceil(y0 + 48 + math.sin(a) * B)
            canvas.create_line(x0, y0, x, y, fill='red')
        for j in range(51):
            a = (2 * math.pi / 16) * i + (2 * math.pi / 180) * k - 1
            x = math.ceil(x0 + 48 * math.cos(a))
            y = math.ceil(y0 + 48 * math.sin(a) * B)
            canvas.create_line(x0, y0, x, y, fill='red')
    mainloop()
Esempio n. 2
0
def ex65():
    screenx = 400
    screeny = 400
    canvas = Canvas(width=screenx, height=screeny, bg='white')

    AspectRatio = 0.85
    MAXPTS = 15
    h = screeny
    w = screenx
    xcenter = w / 2
    ycenter = h / 2
    radius = (h - 30) / (AspectRatio * 2) - 20
    step = 360 / MAXPTS
    angle = 0.0
    for i in range(MAXPTS):
        rads = angle * math.pi / 180.0
        p = PTS()
        p.x = xcenter + int(math.cos(rads) * radius)
        p.y = ycenter - int(math.sin(rads) * radius * AspectRatio)
        angle += step
        points.append(p)
    canvas.create_oval(xcenter - radius, ycenter - radius,
                       xcenter + radius, ycenter + radius)
    for i in range(MAXPTS):
        for j in range(i, MAXPTS):
            canvas.create_line(points[i].x, points[i].y, points[j].x, points[j].y)

    canvas.pack()
    mainloop()
Esempio n. 3
0
class App:
    def __init__(self):
        self.win = tk.Tk()
        self.win.geometry("640x400")
        self.canvas = Canvas()
        self.canvas.pack()
        self.scr = TurtleScreen(self.canvas)

        self.t = RawTurtle(self.scr)
        self.btn = Button(self.win, text="Press me!", command=self.do_action())
        self.btn.pack()

    def do_action(self):
        self.t.pensize(3)
        self.t.pencolor(random.choice(colors))
        self.t.speed(0)

        self.length = 5
        while self.length < 500:
            self.t.left(89)
            self.t.forward(self.length)
            self.t.right(-105)
            self.t.forward(self.length)
            self.length += 3

    def run(self):
        self.win.mainloop()
Esempio n. 4
0
def ex63():
    x, y = 360, 160
    top = bottom = y - 30

    canvas = Canvas(width=400, height=600, bg='white')
    for i in range(20):
        canvas.create_oval(250 - top, 250 - bottom, 250 + top, 250 + bottom)
        top -= 5
        bottom += 5
    canvas.pack()
    mainloop()
Esempio n. 5
0
def ex64():
    canvas = Canvas(width=400, height=600, bg='white')
    left, right, top, num = 20, 50, 50, 15
    for i in range(num):
        canvas.create_oval(250 - right, 250 - left, 250 + right, 250 + left)
        canvas.create_oval(250 - 20, 250 - top, 250 + 20, 250 + top)
        canvas.create_rectangle(20 - 2 * i, 20 - 2 * i, 10 * (i + 2), 10 * (i + 2))
        right += 5
        left += 5
        top += 10
    canvas.pack()
    mainloop()
Esempio n. 6
0
def ex58():
    root = Tk()
    root.title('Canvas')
    canvas = Canvas(root, width=400, height=400, bg='yellow')
    x0 = y0 = 263
    x1 = y1 = 275
    for i in range(19):
        canvas.create_rectangle(x0, y0, x1, y1)
        x0 -= 5
        y0 -= 5
        x1 += 5
        y1 += 5
    canvas.pack()
    mainloop()
Esempio n. 7
0
def ex57():
    canvas = Canvas(width=300, height=300, bg='green')
    canvas.pack(expand=YES, fill=BOTH)
    x0 = y0 = 263
    x1 = y1 = 275
    for i in range(19):
        canvas.create_line(x0, y0, x0, y1, width=1, fill='red')
        x0 -= 5
        y0 -= 5
        x1 += 5
        y1 += 5
    x0 = y0 = 263
    y1 = 275
    for i in range(21):
        canvas.create_line(x0, y0, x0, y1, fill='red')
        x0 += 5
        y0 += 5
        y1 += 5
    mainloop()
Esempio n. 8
0
def draw(lines):
    from tkinter import Tk, LEFT
    from turtle import Canvas, RawTurtle, TurtleScreen

    # set up the environment
    root = Tk()
    canvas = Canvas(root, width=800, height=800)
    canvas.pack()

    s = TurtleScreen(canvas)

    t = RawTurtle(canvas)
    t.speed(0)
    t.width(1)

    for line in lines:
        x, y = line[0]
        t.up()
        t.goto(x * 800 / 1024 - 400, -(y * 800 / 1024 - 400))
        for point in line:
            t.down()
            t.goto(point[0] * 800 / 1024 - 400, -(point[1] * 800 / 1024 - 400))

    s.mainloop()
Esempio n. 9
0
            # remove cars that drove out of the scene
            if (car.pos_x < 0 or car.pos_x > width or car.pos_y < 0
                    or car.pos_y > height):
                cars.remove(car)

        canvas.update()
        time.sleep(0.01)


if __name__ == '__main__':
    root = Tk()

    # main global variables
    width = root.winfo_screenwidth()
    height = root.winfo_screenheight()
    roadWidth = 300

    #  canvas is a white piece of paper on which you can draw
    canvas = Canvas(root, width=width, height=height, bg="dimgrey")
    canvas.pack()

    # list of cars in the scene
    cars = []

    # run the simulation
    simulate_cars()

    # must be the last line before exit for TKinter
    root.mainloop()
Esempio n. 10
0
obj3 = IssueBook()
obj4 = Return()

root = Tk()
root.title("Library")
root.minsize(width=400, height=400)
root.geometry("600x500")
photo = ImageTk.PhotoImage(file="libicon.png")
root.iconphoto(False, photo)
#root.mainloop()
same = True
n = 0.25

# Adding a background image
canvas = Canvas(root)
canvas.pack(expand=YES, fill=BOTH)

image = ImageTk.PhotoImage(file="lib.jpg")
canvas.create_image(10, 10, image=image, anchor=NW)
#Adding a header
headingFrame1 = Frame(root, bg="#FFFFFF", bd=5)
headingFrame1.place(relx=0.2, rely=0.1, relwidth=0.6, relheight=0.16)
headingLabel = Label(headingFrame1,
                     text="Welcome to \n the Library",
                     bg='black',
                     fg='white',
                     font=('Courier', 15))
headingLabel.place(relx=0, rely=0, relwidth=1, relheight=1)

btn1 = Button(root,
              text="Add Book Details",