-1

3 つの引数 (左上隅の x 座標と y 座標、および辺の長さ) を取る create_square という関数を実装します。定義済みの tkinter 関数 create_rectangle を呼び出します。

import tkinter
def create_square (x: int, y: int, s: int):
    '''Return a square on tkinter given the x-coordinate and
    y-coordinate of the upper-left corner and length of a side'''
    return(create_rectangle(x, y, s))

エラーとして表示されますが、他にこれを行う方法がわかりません。

4

1 に答える 1

1

これを試して:

from tkinter import Tk, Canvas

tk = Tk()
canvas = Canvas(tk, width=500, height=500)
canvas.pack()

def create_square(x1,y1,side):
    x2 = x1 + side
    y2 = y1 + side
    canvas.create_rectangle(x1, y1, x2, y2)

create_square(100, 100, 200)
tk.mainloop()
于 2015-10-10T14:46:12.953 に答える