Sep-29-2017, 12:51 PM
Hello,
I have a Tkinter script which creates 15 instances of some entry boxes and two optionmenu widgets (all with the same lists). I know it's not the right way to to it, and am pretty sure sure there is a better way to set everything up than repeating all the code 15 times (which is what I did just to get the app completed on schedule).
I would think something like below might work:
Am I wrong in assuming that there is way to do this without repeating the same things 15 times?
Thank you for any input!
I have a Tkinter script which creates 15 instances of some entry boxes and two optionmenu widgets (all with the same lists). I know it's not the right way to to it, and am pretty sure sure there is a better way to set everything up than repeating all the code 15 times (which is what I did just to get the app completed on schedule).
I would think something like below might work:
import tkinter as tk optionsx = ["Select a Category","Item 1", "Item 2", "Item 3"] for n in range(1,16): Category(n) = tk.StringVar(root) Category(n).set(optionsx[0])Which the optimist in me expected to produce:
Category1 = tk.StringVar(root) Category2 = tk.StringVar(root) Category3 = tk.StringVar(root) ... Category1.set(optionsx[0]) Category2.set(optionsx[0]) Category3.set(optionsx[0]) ...But I'm getting the error
Quote:SyntaxError: can't assign to function call
Am I wrong in assuming that there is way to do this without repeating the same things 15 times?
Thank you for any input!