Skip to content
Advertisement

How to generate “n” rows of Entry boxes from another Entry box?

I want to get an integer from an entry field and create new entry boxes below that. I have written a code to do that using a button. However, I want to make it happen automatically without a button as I entered the number, the rows update.

I saw one way to automate it is using the callback.

JavaScript

So, I changed the code to the below one using callback.

JavaScript

When I enter a number, it works and an error raises: _tkinter.TclError: expected floating-point number but got "" which I don’t know what is that for.

Also, the code only works when I put numbers in ascending format. forexample, if I first enter 5, then change it to 3 it doesn’t work.

Advertisement

Answer

You should use StringVar to associate with the Entry, as the entry contains text.

There is a method in StringVar to trace any changes: StringVar().trace(). Se example code below:

JavaScript

The error you get is because the Entry contains text. You will have to convert it to int before you use it.

New example

You could do this in many ways, but here is one example:

JavaScript

Is that what you had in mind?

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement