Hi guys I am looking to create the following as shown below. Anybody able to give me a hand as im really struggling to make the rectangles different lengths.

Red rectangles looks same size for me and spacing is also constant.
Role of spacing rectangles and red rectangles only alternate with spacing white ones. 3 white, 3 red, 3 white ....

Swap the spacing and rectangles after each line:

rect, spacing = spacing, rect

I don't have a lot of time, but here is a simple example to start you, using Tkinter. The other GUI toolkits, WxPython and QT, would be similar.

from Tkinter import *

root = Tk()
root.title('Rectangle Test')
canvas = Canvas(root, width =300, height=300)

## top_left_x, top_left_y, bottom_right_x, bottom_right_y
points_list = [0, 0, 25, 25]
color = "red"

for row in range(3):
    for col in range(3):
        rectang = canvas.create_rectangle(points_list[0], points_list[1], \
                              points_list[2], points_list[3], fill=color)
        ## increase along the x axis
        for point in [0, 2]:
            points_list[point] += 50

    ## move down one row
    if row%2:      ## row is an odd number
        points_list = [ 0, points_list[1]+25, 25, points_list[3]+25]
    else:          ## row is an even number
        points_list = [25, points_list[1]+25, 50, points_list[3]+25]

canvas.pack()
root.mainloop()

Cheers for your help guys. Not sure what Tkinter is as i am using the graphics module anybody have any help using the graphics module.

Anybodyy? really need help with this

The middle rectangle, be it red or white is centered, so if you have a 200x200 canvas, the middle would be 100. You can then move left or right, calculating the end position of the first red square for the rows with 4 red squares; end position=middle - (1.5 white + 1 red). The other row is obviously rectangles of the same size.

Anybodyy? really need help with this

Post you code for drawing a single rectangle, the rest will be easy.

Cheers for your help guys. Not sure what Tkinter is as i am using the graphics module anybody have any help using the graphics module.

John Zelle, Ph.D. teaches Python at Wartburg College
He is the author of graphics.py used by a number of schools instead
of Tkinter


Get the graphics module (a thin wrapper for Tkinter) here ...
http://mcsp.wartburg.edu/zelle/python/graphics.py

also has a nice documentation ...
http://mcsp.wartburg.edu/zelle/python/graphics/graphics.pdf

i Think graphics modules is taken more seriously for college guys thank tkinter the main module.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.