如何将输入与TKINTER中的条目分为单个字符?

发布于 2025-02-03 06:47:29 字数 144 浏览 4 评论 0原文

我正在努力在TKINTER中制作一个密码程序,需要将输入到分开字符的条目中分开。

例如,如果用户输入“猴子”一词, 它将被放入这样的阵列 seperatedword = [“ m”,“ o”,“ n”,“ k”,“ e”,“ y”]

我该怎么做?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

清风疏影 2025-02-10 06:47:29

正如ACW1668所评论的那样。

separatedWord = list(input_word)

您可以 typecast> typecast 字符串作为

列表代码:

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()

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()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文