json 我得到这个错误TypeError:“module”对象在Python中不可调用

zynd9foi  于 2023-07-01  发布在  Python
关注(0)|答案(1)|浏览(124)

我试着用json和python创建一个字典,但我得到了这个错误TypeError: 'module' object is not callable
我该怎么办

from tkinter import * 
from tkinter import ttk
import path
import json

data = path("json.json").()
word_list = json.loads(data)

from tkinter import * 
from tkinter import ttk
import path
import json

data = path("json.json").()
word_list = json.loads(data)

class root(Tk):
  def __init__(self):
    super().__init__()
    self.title('dictionery')
    self.minsize(380, 250)
    self.labels()
    self.dictionary()

  def labels(self):

    self.Label_1 = ttk.Label(self, text='serch')
    self.Label_1.grid(column=3, row= 0, padx= 55)  

    self.Entry_1 = Entry(self)
    self.Entry_1.grid(column=3 , row = 1, padx= 50)

    self.listBox = Listbox(self, height= 10, width= 40)
    self.listBox.grid(column=3, row= 3, padx= 60)

    self.button = ttk.Button(self, text= 'serch')
    self.button.place(x= 250, y=14)

  def dictionary(self):
    word = self.Entry_1.get()
    meanings =word_list[word]
    for meaning in meanings:
        self.listBox.insert(END, meaning)

window = root()
window.mainloop()
fbcarpbf

fbcarpbf1#

我怀疑这个问题是由import path引起的,它是无效的。您实际上可能需要的是from pathlib import Path
而且data = path("json.json").()结尾的额外括号也是一个问题。

from tkinter import * 
from tkinter import ttk
from pathlib import Path  # import the 'Path' class from the 'pathlib' module
import json

file_path = Path(r'json.json')  # instantiate the 'Path' class here (capital "P")

with open(file_path, 'rb') as json_file:
    word_list = json.load(json_file)

相关问题