I am new to python, but have years of experience in C, C++, C#, and a few other languages. I am trying to write code that can be reused by different programs. Each program will have different number of buttons, different names, and different methods assigned to the button. All the data will be a json file. I able to create the correct number of buttons, assign the correct name, and even assign a correct tooltip. I am not able to dynamically assign to the command=. All the methods are defined.
My question is it possible to dynamically assign a string to command=? I think not, but would like someone with more python experience to tell me I can't. Here is the code:
diagnosticButtons = get_diagnostic_buttons(str(Path(__file__).parent)) # get the list of diagnostic buttons
xCoordinate = 20;
yCoordinate = 20;
iStep = 30
iOffset = 60
iXCount = 0;
iYCount = 0;
for i in diagnosticButtons:
diagName = i["name"]
toolTip = i["tooltip"]
method = i["method"] # method name to assign to commmand
xPosition = xCoordinate + (iOffset * iXCount)
yPosition = yCoordinate + (iStep * iYCount)
diagButton = Button(diagFrame, text=diagName, command=method, height=1, width=6)
diagButton.place(x=xPosition, y=yPosition)
Tooltip(diagButton, text=toolTip)
iYCount = iYCount + 1
if iYCount == 12: # end of the space
iYCount = 0 # set y back to beginning
iXCount = iXCount + 1 # increment the x