Skip to content Skip to sidebar Skip to footer

How To Draw More Than One Square In Tkinter's Canvas?

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(

Solution 1:

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.


Solution 2:

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


Post a Comment for "How To Draw More Than One Square In Tkinter's Canvas?"