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()
这将创建一个正方形/矩形。如何创建一个函数以创建多个正方形?
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()
这将创建一个正方形/矩形。如何创建一个函数以创建多个正方形?
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并不难。
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