I'm very fresh to Python and I'm currently trying to write a simple tkinter program for creating template descriptions for password reset report tickets. It will pick up one of the variants from the passOptions list, and afterwards from that option it'll show in the drop down menus, which can be modified and moved to the text box below for a quick copy-paste. The code can be seen below, with one option to make it less confusing:
from tkinter import *
from tkinter import ttk
root = Tk()
root.title("Passcode templates generator")
root.geometry("800x800")
def passOptionsSelected(event):
if passOptionsVar.get() == passOptions[1]:
def passOptionPrintOut(*args):
the3PUIsString['text'] = f'Customer\'s identity validated w/ 2 PUI\'s? - {the3PUIsVar.get()}\n'
restOfThePRTextBox = Text(root, height=12, width=90)
restOfThePRTextBox.place(x=10, y=100)
restOfThePRTextBox.insert('1.0', the3PUIsString)
the3PUIsLabel = Label(root, text="Customer's identity validated w/ 2 PUI's?").place(x=10, y=45)
the3PUIsOptions = ('How many?', '3PUIs.', '2PUIs.', '1PUIs.', 'None.')
the3PUIsString = " "
the3PUIsVar = StringVar()
the3PUIsDropdown = ttk.OptionMenu(root,
the3PUIsVar,
the3PUIsOptions[0],
*the3PUIsOptions,
command=passOptionPrintOut)
the3PUIsDropdown.place(x=300, y=40)
passOptions = ["Select...", "Option 1", "Option 2"]
passOptionsVar = StringVar()
passOptionsDropdown = ttk.OptionMenu(root,
passOptionsVar,
passOptions[0],
*passOptions,
command=passOptionsSelected)
passOptionsDropdown.place(x=10, y=10)
root.mainloop()
Now whenever the program selects the option from the3PUIsOptions it keeps giving me the "TypeError: 'str' object does not support item assignment in a list" and won't add it to the text box in the passOptionPrintOut function. Should that list be changed to a dictionary instead, or is there a different way do get the separate string from that list?
the3PUIsString? If it's aLabel, why do you havethe3PUIsString = " "? If it's astring, why do you havethe3PUIsString['text'] = ...?