chernoobyl
chernoobyl

Reputation: 1

TypeError: list indices must be integers, not float - Variables in Tkinter

I'm new to programing so forgive me if my questions are on the obvious side. Essentially I am trying to create a basic polar coordinate system for use in Tkinter, however, I'm having some issues with it.

Here are the relevant bits of code:

def polar(self, theta, radius, xC, yC):
    thetarad = -theta * (math.pi / 180)
    xprime = xC + math.cos(thetarad) * radius
    yprime = yC + math.sin(thetarad) * radius
    return (xprime, yprime)

def draw(self, c):        

    # create X-coordinate guide list
    xspaces = 55    # number of guides in the guide list
    xgridwidth = 1.0 * self.width / xspaces
    x = []
    for i in range(xspaces+1):
        x.append(self.left + i*xgridwidth)

    # create Y-coordinate guide list
    yspaces = 100    # number of guides in the guide list
    ygridwidth = 1.0 * self.height / yspaces
    y = []
    for i in range(yspaces+1):
        y.append(self.top + i*ygridwidth)


    xC = x[30]
    yC = y[25]

    theta = 0
    radius = 15
    [xprime, yprime]=self.polar(theta, radius, xC, yC)
    petalp1 = (  (x[xprime], y[yprime])  )

The top and bottom most parts are what I'm getting the errors with. Essentially I just need xprime and yprime to come back as integer numbers so they can be used just as well as raw numbers when establishing p1. Help is appreciated.

Full error:

    Traceback (most recent call last):
  File "E:FileName.py", line 34, in <module>
    daisy.draw(c)
  File "E:FileName2.py", line 174, in draw
    petalp1 = (x[int(xprime)], y[int(yprime)])
IndexError: list index out of range

Upvotes: 0

Views: 405

Answers (1)

furas
furas

Reputation: 142631

Seems int(xprime) is bigger then xspaces (value: 55) and int(yprime) is bigger then yspaces (value: 100) so you try to get values not existing in list x (length: 55) and in list y (length: 100) ( x[int(xprime)] and y[int(yprime)] )

Upvotes: 1

Related Questions