Making a random coordinate generator
<p>This code was originally meant for user input, however I want it to randomly create a polygon rather than manually selecting points myself.<br>
I'll probably make it a for loop, rather than a while loop so you don't need to mention that.</p>

<pre><code>import pygame
from pygame.locals import *
from sys import exit
import random
from random import *

pygame.init()
screen = pygame.display.set_mode((640, 480), 0, 32)
points = []


while True:

    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            exit()
        point1 = randint(0,639)
        point2 = randint(0,479)
        points = (str(randint(0,639)), str(randint(0,479)))

    screen.fill((255,255,255))

        if len(points) &gt;= 3:
            pygame.draw.polygon(screen, (0,255,0), points)
        for point in points:
            pygame.draw.circle(screen, (0,0,255), point, 5)

            pygame.display.update()
</code></pre>

<p>What I am attempting to do is to make a coordinate point randomizer.<br>
However, it isn't compatible with this code for some reason. I tried other things as well, and remnants of those attempts may be visible.<br>
The segment I changed goes from the <code>for event in pygame.event.get</code>to the <code>screen.fill((255,255,255))</code>.<br>
The original code was like this:</p>

<pre><code>while True:
    for event in pygame.event.get():
        if event.type == QUIT:
        pygame.quit()
        exit()

    if event.type == MOUSEBUTTONDOWN:
        points.append(event.pos)

    screen.fill((255,255,255))
</code></pre>

<p>When I run the program, I get a</p>

<pre><code>Traceback (most recent call last):
  File "H:/Documents/it/Python/manual_box drawer.py", line 26, in &lt;module&gt;
    pygame.draw.circle(screen, (0,0,255), point, 5)
TypeError: must be 2-item sequence, not int
</code></pre>

<p>error report.</p>

<p>I think this </p>

<pre><code>points = (str(randint(0,639)), str(randint(0,479)))
</code></pre>

<p>Should be written like so (the extra comma makes a tuple). You need to append to the <code>points</code> list rather than re-assign the variable. </p>

<pre><code>points.append( (point1, point2,) )
</code></pre>

<p>Then you can loop over <code>points</code> and draw them like you are already trying to do. </p>

python random coordinates