Re: [Tutor] Empty GraphicsWindow

2014-11-21 Thread Alan Gauld

On 21/11/14 03:00, niyanax...@gmail.com wrote:

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


Since 'graphics' is not a standard part of Python can you tell
us where you are getting it from? Thee are at least 2 graphics
modules out there, probably more.


tileSize = 0

def main() :


 ...


 # 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()


What does win.wait() do? Usually there is some kind of refresh() or 
update command to force a canvas to redraw itself. wait() sounds more 
like it just leaves the window in-situ until something closes it?


But without knowing anything about your library its hard to be sure.

You may have more luck finding an expert by contacting a forum for
your specific graphics package.

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my phopto-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Empty GraphicsWindow

2014-11-20 Thread niyanaxx95
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___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor