0

I want to first say I know that other people have had this problem, but I've looked through the responses to them and none of them has been similar enough to help me solve it.

I'm trying to trace an Entry box, and if the Entry is the right size go through a SQL database and find a corresponding value.

https://i.stack.imgur.com/egSX6.png is the GUI, the fields with the $ should update if criteria are filled.

I added this code to check the Entry:

def update_winner():
    cursor = conn.cursor()
    winner = winner_id.get()
    school = school_name.get()
    temp = school+winner

    if len(temp) == 5:

        cursor.execute("SELECT Rating FROM KIDS WHERE LocalID = ?", temp)
        rating=cursor.fetchval()
        cursor.execute("SELECT FirstName FROM KIDS WHERE LocalID = ?", temp)
        name=cursor.fetchval()

        winner_name.set(name)

winner_id.trace("w",update_winner)

ratings.mainloop()

When I run it, the instant I put anything into the Entry that feeds to winner_id I get the following error: TypeError: update_winner() takes 0 positional arguments but 3 were given.

Where are the arguments to update_winner() coming from? It's being called in the trace method and I don't think I'm passing anything.

user3364161
  • 365
  • 5
  • 21

1 Answers1

1

When the StringVar content is modified, the update_winner function is called with 3 arguments (see What are the arguments to Tkinter variable trace method callbacks? for more details). Since your function does not take any argument, it gives you the error TypeError: update_winner() takes 0 positional arguments but 3 were given.

To correct it, just change def update_winner(): in def update_winner(*args):.

Community
  • 1
  • 1
j_4321
  • 15,431
  • 3
  • 34
  • 61
  • Ok perfect, that worked. Although I don't really understand what *args does. Can you explain what that is? – user3364161 Feb 07 '17 at 17:06
  • 1
    @user3364161 If the question is what `*args` does in general: http://stackoverflow.com/questions/36901/what-does-double-star-and-star-do-for-parameters – j_4321 Feb 07 '17 at 17:38