0

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?

2
  • 1
    What is the3PUIsString? If it's a Label, why do you have the3PUIsString = " "? If it's a string, why do you have the3PUIsString['text'] = ...? Commented Sep 12, 2022 at 12:09
  • Oh, it worked out, by simply removing the "[text]" from "the3PUIsString". Thank you so much for pointing it out! It was for adding the text from that list, with additional string defined in the function. Commented Sep 12, 2022 at 12:14

1 Answer 1

2

Had to change the

the3PUIsString['text']

into

the3PUIsString

instead, and now it can add them.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.