# [Tutor] Empty GraphicsWindow

niyanaxx95 at gmail.com niyanaxx95 at gmail.com
Fri Nov 21 04:00:42 CET 2014

```I need help figuring why my GraphicsWindow empty, I cannot figure out why it is empty.

Here is my code :

# Import graphics from module
from graphics import GraphicsWindow

tileSize = 0

def main() :

# Define global variables
tilesInRow = 0
tilesInCol = 0
gapX = 0
gapY = 0

# Input room width
roomWidth = getNumber(100, 500, "Enter a room width between 100 and 500: ", "")
roomLength = getNumber(100, 450, "Enter a room length between 100 and 450: ", "")
tileSize = getNumber(20, 50, "Enter a tile size between 20 and 50: ", "")

numCols = tilesForSize(roomWidth, tileSize)
print("The total number of Columns:", numCols)
numRows = tilesForSize(roomLength, tileSize)
print("The total number of Rows:", numRows)

# Print the total number of tiles
print("The total number or Tiles: %d" %(numCols * numRows))

# Calculate the gap
# the gap = (the total width - the number of tiles * tile width / 2

gapX = calculateGap(roomWidth, numCols)
gapY = calculateGap(roomLength, numRows)

# Print the gaps
print("The gap at each end of a row is: %.1f" % (gapX))
print("The gap at each end of a column is: %.1f" % (gapY))

# Draw graphics window
win = GraphicsWindow(roomWidth, roomLength)
canvas = win.canvas()

# Draw the checkered surface
for row in range(numRows) :
# If the row is even
if row % 2 == 0 :
# If the column is even set color to black, if odd yellow
drawRow(canvas, row, gapX, numCols, gapY, "black", "yellow")

# If the row is odd
else:
# If the column is even set color to yellow, if odd black
drawRow(canvas, row, gapX, numCols, gapY, "yellow", "black")

win.wait()

def getNumber(minBound, maxBound, msg, err_msg) :
num = minBound - 1
while num < minBound or num > maxBound :
if(msg == "") :
num = float(input("Enter a number between %f and %f: " % (minBound, maxBound)))
else :
num = float(input(msg))
if num < minBound or num > maxBound :
if err_msg == "" :
print("Invalid input.")
else:
print(err_msg)
return num

def tilesForSize(size, tileSize) :
pairs = int(size - tileSize) // int(2 * tileSize)
num = int(1 + (2 * pairs))
return num

def calculateGap(size, num) :
return (size - num * tileSize) / 2

def drawRow(canvas, row, gapX, numCols, gapY, color1, color2) :
for col in range(numCols) :
if col % 2 == 0 :
canvas.setColor("black")
else:
canvas.setColor("yellow")
# Draw the actual rectangle
canvas.drawRect(row * tileSize + gapX, col * tileSize + gapY, tileSize, tileSize)

main ()

Sent from Windows Mail
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20141121/46c537a8/attachment-0001.html>
```