0

I am working on a tkinter project and am having issues creating a number of buttons using a for loop. When I try to create buttons within a loop, I get the error 'list' object has no attribute 'tk'. I am using two lists generated from a table in db browser which I have shown below. The second part is where the error is occuring. If I remove the RewardButton generator, then no error occurs so I believe it takes issue with this specific line

    conn = sqlite3.connect("Scheduling.db")
    c = conn.cursor()
    c.execute("select reward from rewards where Cu_ID=?",(ID))
    rewards = c.fetchall()
    c.execute("select points from rewards where Cu_ID=?",(ID))
    points = c.fetchall()
    c.close()
    rewardlist=[]
    for l in rewards:
        rewardlist.append(l)
    pointlist=[]
    for p in points:
        pointlist.append(p)
buttonnum=len(rewardlist)
    for x in range(buttonnum):
        rowpos = x+5
        reward = rewardlist[x]
        point = pointlist[x]
        RewardButton[x] = Button(rewards, text ="Button",command = lambda k=x: RedeemReward(k))
        RewardButton[x].grid(row=rowpos, column=3)
Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
  • We are missing key parts of your code to understand where the error is coming from, in particular the creation of the Tk window in which the buttons will be put. Please read https://stackoverflow.com/help/minimal-reproducible-example and edit your question to provide a Minimal, Reproducible Example. For instance, I don't think we don't need the code related to the connexion to the database, you can replace it with dummy data in your question. – j_4321 Feb 11 '22 at 16:31

1 Answers1

0

I believe your error is being generated because you are passing rewards, instead of reward, as an argument to your Button() class.

I’m assuming so because you defined reward during that for loop. However, I don’t see rewards defined in your code.