Python TKinter和JSON

Python TKinter和JSON,python,json,tkinter,Python,Json,Tkinter,我正在寻找学习如何连接TKinter和JSON的资源 例如,获取一个输入值单词并在JSON中搜索该单词,然后打印出搜索结果 顺便说一下,我已经有了通过终端运行的python应用程序,但我想进一步构建一个GUI 谢谢, import json #import the JSON module from difflib import get_close_matches #difflib module provides classes and fun

我正在寻找学习如何连接TKinter和JSON的资源 例如,获取一个输入值单词并在JSON中搜索该单词,然后打印出搜索结果 顺便说一下,我已经有了通过终端运行的python应用程序,但我想进一步构建一个GUI 谢谢,

 import json                           #import the JSON module
from difflib import get_close_matches #difflib module provides classes and functions 
                                      #for comparing sequences
                                      #get_close_matches Return a list of 
                                      #the best “good enough” matches

data = json.load(open("data.json"))   #load JSON to python dictionary  

def translate(w): 
    w = w.lower()                     #change the input to lower case
    if w in data:                     #first scenario check if the word exist in the dictionary, if exist load the data
        return data[w]
    elif w.title() in data:           #When the user inputs a proper noun
        return data[w.title()]        #returns the definition of names that start with a capital letter
    elif w.upper() in data:           #definition of acronyms
        return data[w.upper()]
    elif len(get_close_matches(w, data.keys())) > 0: #second scenario compare the word and get the best match
         #ask the user if the result of matching what is looking for 
         YN = input("Did you mean %s instead? Enter y if yes or n if no:" % get_close_matches(w, data.keys())[0])
         if YN == "y":
            return data[get_close_matches(w, data.keys())[0]]
         elif YN == "n":
            return "The word doesn't exist. Please double check it."
         else:
            return "We didn't understand your entry."
    #third scenario the word not match or can't found
    else: 
        return "The word doesn't exsit. Please double check it."


word = input("Enter word: ") 

#in some cases the word have more than one definition so we need to make the output more readable 
output = translate(word)
if type(output) == list:
    for item in output:
        print(item)
else:
    print(output)
下面是如何做到这一点

如果你的当前程序有一个图形用户界面的话,你可以画一些它的样子。 您是说%s吗?是一个弹出框吗? 你能列出所有已知的单词吗? 使用tkinter构建UI。 将UI连接到程序中的函数。你有这些,是吗?
您的程序还没有完全准备好,因为您正在做一些事情,比如在函数中使用输入。修改它,使其在功能之外有意义,然后它可能就准备好了。

请修复问题的格式我修复了,谢谢你的注释有几个tkinter教程。选择一个并完成它。+1:从CLI命令行界面切换到GUI图形用户界面需要一些准备工作来阐明应用程序将如何与用户交互。只有这样,您才能将数据/事件流转换为一组小部件和callbacks@sciroccorics好吧,如果你一开始就写对了程序,那么你就减少了,或者在某些情况下,删除了将程序从一个接口转换到另一个接口所需的准备工作。