Python Forum
[Tkinter] Coding issue
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Coding issue
#1
Hello! I am fairly new to python and i am taking over a project from a previous student. In this portion of the code that I was given, I keep getting an IndexError. If anybody has anything that can help, please feel free. Thank you!



  #Name Labels and Angular Displacement Sliders
        names = ["Servo {}:".format(8-x) for x in range(8)]
        jointLabels = []
        jointScales = []
        for x in range(8):
            jointLabels.append(Tkinter.Label(individualServoControlFrame, text = names[x]))
            jointLabels[x].grid(row = x+1, column = 0, sticky="SE")
            if window.dropBoxServoModelVariable.get() == 'AX-12' or window.dropBoxServoModelVariable.get() == 'AX-18':
                jointScales.append(Tkinter.Scale(individualServoControlFrame, from_ = 0, to = 296.67, resolution = 0.01, width = 15, length = 150, orient = "horizontal")) #Creating sliders
            elif window.dropBoxServoModelVariable.get() == 'MX-28':
                jointScales.append(Tkinter.Scale(individualServoControlFrame, from_ = 0, to = 360.36, resolution = 0.01, width = 15, length = 150, orient = "horizontal")) #Creating sliders
                
            jointScales[x].grid(row = 8-x, column = 1)  <----------(THIS IS THE LINE THAT KEEPS GETTING THE ERROR)
            
        setattr(window, "jointScales", jointScales)
        setattr(window, "jointLabels", jointLabels)
Reply
#2
You have an if and elif to append to jointScales. If neither is true then you don't have a jointScales[x]. Add an else to print some error message when this happens. In the future, post the complete traceback error message. "(THIS IS THE LINE THAT KEEPS GETTING THE ERROR" is rarely enough info to be in any way helpful.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020