Example #1
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()
def start():
    window = Tk()
    window.title("SYSC 3310 Final Project: State toggling")
    window.geometry('325x150')

    # Creates the buttons
    backwards = Button(window,
                       text="Move Backwards",
                       command=lambda: sendCommand('1'))
    forwards = Button(window,
                      text="Move Forwards",
                      command=lambda: sendCommand('2'))
    reset = Button(window,
                   text="Reset Board",
                   command=lambda: sendCommand('0'))

    backwards.grid(column=0, row=0, padx=5, pady=2)
    forwards.grid(column=1, row=0, padx=5, pady=2)
    reset.grid(column=2, row=0, padx=5, pady=2)

    # Creates the boxes to display the current state
    global lbl
    lbl = Label(window, text="Just initialized")
    currState = Label(window, text="Current State: ")

    lbl.grid(column=1, row=1)
    currState.grid(column=0, row=1)

    # Creates the canvas, rectangle used for the UI display
    global canvas
    canvas = Canvas(window)
    canvas = Canvas(width=75, height=100)
    canvas.grid(column=0, row=4)

    global rectangle1
    global rectangle2
    rectangle1 = canvas.create_rectangle(5, 25, 25, 45, fill='black')
    rectangle2 = canvas.create_rectangle(30, 25, 50, 45, fill='black')

    canvas.create_text(15, 10, fill="black", font="Times 8 bold", text="P1.0")
    canvas.create_text(40, 10, fill="black", font="Times 8 bold", text="P2.0")

    # Sets up the receive thread
    receiveThread = threading.Thread(target=receiveState)
    receiveThread.daemon = True
    receiveThread.start()

    # Returns the board to its base state (state 1)
    # Optional
    sendCommand(INITIAL_STATE)

    window.mainloop()
Example #3
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()