Python tkinter如何使用输入到条目小部件中的内容

2024-09-30 07:30:42 发布

您现在位置:Python中文网/ 问答频道 /正文

如何在程序的其余部分使用输入Tkinter entry小部件的内容? 我有这个条目:

n = StringVar()
Entry(search1, textvariable=n).pack()
label = n.get()

with open('data.txt') as json_file:
    data = json.load(json_file)
    for p in data:
        recipe = p['recipe']
        recipeNames= recipe['label']
        if recipeNames == label:
            recipeName = label
            ingredients = []
            for j in recipe['ingredients']:
                ingredients.append(j['text'])
Button(search1, text="Enter", command=partial(addrecipe, recipeName, calendarID, ingredients, service)).pack()

当我尝试使用变量时,它没有任何内容,并且返回时出错。如何将变量分配给条目小部件中的内容


Tags: injson内容fordata部件recipe条目

热门问题