-1

I am working on making a ciphering program in Tkinter and need to seperate the words inputted into an Entry into seperate characters.

For example, if the user inputted the word "monkey", it would be put into an array like this seperatedWord = ["m","o","n","k","e","y"]

How would I go about doing this?

HarrisonT
  • 45
  • 9

1 Answers1

2

as commented by acw1668.

separatedWord = list(input_word)

you can typecast a string as list

try this code:

from tkinter import *


class MyEntry(Entry):
    def __init__(self, root, textvariable):
        Entry.__init__(self, master=root, textvariable=textvariable)

        #binding your trace handler to your textvariable
        textvariable.trace_add("write", self._traceHandler)

    #or just use this handler
    def _traceHandler(self, x, y, z):
        # code block
        print(self.getSeparatedWord())

    #you can call this
    def getSeparatedWord(self):
        value = self.get()
        return list(value)


root = Tk()
my_textvar = StringVar()
my_entry = MyEntry(root, my_textvar)
my_entry.pack()
root.mainloop()
Jay Dee
  • 51
  • 3
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 30 '22 at 08:27