Reputation: 785
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()
This creates one square/rectangle. How do I create a function so that it will create more than one square?
Upvotes: 1
Views: 18844
Reputation: 1180
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
Upvotes: 0
Reputation: 4975
How about calling create_rectangle
repeatedly?
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()
Maybe you should put a little more effort into it, it is not that hard to go from making one to makeing n.
Upvotes: 5