0
from Tkinter import Tk, Canvas


master = Tk()
w = Canvas(master, width=250, height=200)
w.pack()
w.create_rectangle(0, 0, 100, 100, fill="blue", outline = 'blue')
master.mainloop() 

这将创建一个正方形/矩形。如何创建一个函数以创建多个正方形?

4

2 回答 2

3

create_rectangle反复打电话怎么办?

from Tkinter import *
master = Tk()

w = Canvas(master, width=250, height=200)
w.create_rectangle(0, 0, 100, 100, fill="blue", outline = 'blue')
w.create_rectangle(50, 50, 100, 100, fill="red", outline = 'blue') 
w.pack()
master.mainloop()

也许你应该多花点力气,从做一个到做n并不难。

于 2013-03-09T08:52:59.980 回答
0

Read up on how to define functions in Python. I recommend the official tutorial.

Implementing the rectangle as a class (NOTE: For your own sake, read about functions and variables first): Help Creating Python Class with Tkinter

于 2013-03-09T09:00:43.243 回答