在从 tkinter 文本小部件检索的列表上运行函数

问题描述

我无法将我的函数应用到我从我的 tkinter 文本小部件中检索的列表。该列表通过按钮 command=lambda: get_list()) 检索。我正在尝试应用 def func_1():,但它没有抛出错误,它只是在我输入任何数据之前立即运行它。

dictionary = {
    'A': '1','B': '2','C': '3'}

def get_list():
    text_input = text.get("1.0","end-1c").split("\n")
    return text_input


def func_1(text_input):
    x=0
    while x < len(text_input):
        text_replace = (text_input[x]).replace(',','')
        text_split = text_replace.split()
        not_found = True
        for key in dictionary:
            if key in text_split:
                result = dictionary[key]
                return (result)
                not_found = False
                break
        if not_found :
            return ("Some Error Message")
        x = x + 1
print(func_1(get_list()))

如果我输入几行;

 1. A,D,E
 2. B 
 3. C

它跳过 func_1,并说明 if not found 文本:

Some Error Message

我需要它来 get 文本小部件输入,在 "\n" 处拆分为一个列表,并在与输入小部件的行一样多的项目上运行 func_1

func_1 应该获取每个列表项,替换所有逗号,然后将其拆分为自己的 for 循环列表。

我不知道如何以不同的方式分解它。

感谢您的建议!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)