I'm trying to develop a function which creates a new tab with many Tkinter objects (labels, buttons, spinboxes, etc.). Afterwards to assign this function to many buttons (with the button's number as the function's parameter) located in the root window. What I want to do is to rename variables inside the function's body by adding to their original names a suffix which is the function's parameter. Moreover, one of the variables is global (used as a counter).
var_1 = 0
var_2 = 0
def relay_btn(relay_number):
var_n = 'var_' + str(relay_number)
global var_n
vars()[var_n] = 0 + relay_number
relay_btn(1)
relay_btn(2)
print(var_1)
print(var_2)
As a result, I'd like to see 1 and 2, respectively, not 0.