Вот код:
import tkinter as tk
import json
def save_js(texti, txt):
with open('file.json', 'r') as statham:
data = json.load(statham)
data['user'].append({'text' : texti, 'txt' : txt})
with open('file.json', 'w') as statham:
json.dump(data, statham, indent=4)
class HelpMenu(tk.Tk):
def __init__(self, frame, text2):
super().__init__()
self.text2 = text2
self.frame = frame
self.button = tk.Button(self, text='Удалить', command=self.delet)
self.button.pack()
self.button2 = tk.Button(self, text='Посмотреть', command=self.see)
self.button2.pack()
def delet(self):
self.frame.destroy()
self.destroy()
def see(self):
self.destroy()
tak = tk.Tk()
label = tk.Label(tak, text=self.text2)
label.pack()
class NewPlus(tk.Tk):
def __init__(self, frame, count):
super().__init__()
self.frame = frame
self.count = count
self.geometry('400x300+400+300')
self.butt = tk.Button(self, text='-->', command=self.delete)
self.butt.place(x=350, y=150)
self.label = tk.Label(self, text="Введите название")
self.label.place(x=30, y=10)
self.config(bg='gray')
self.entr = tk.Entry(self, width=55)
self.entr.place(x=30, y=50, height=40)
self.entr.bind('<KeyPress>', self.foo2)
self.text = tk.Text(self, width=35, height=10)
self.text.place(x=30, y=130)
self.label2 = tk.Label(self, text='Введите текст')
self.label2.place(x=30, y=100)
self.overrideredirect(True)
def delete(self):
self.infosave()
self.destroy()
def foo2(self, e):
self.entr.delete('30', tk.END)
def infosave(self):
self.texti = self.entr.get()
self.txt = self.text.get(0.0, tk.END)
self.save_json()
Todo(text=self.texti, frame=self.frame, count=self.count, text2=self.txt)
def save_json(self):
save_js(self.texti, self.txt)
class App(tk.Tk):
def __init__(self):
super().__init__()
self.count = -1
self.todomag()
self.window = self
self.button = tk.Button(self, text='Добавить',
width=8,
command=self.command)
self.button.place(x=550, y=400)
self.frame = tk.Frame(self, borderwidth=1, relief='solid', height=430, width=500)
self.frame.place(x=30, y=30)
def command(self):
self.count += 1
NewPlus(self.frame, self.count)
def todomag(self):
with open('file.json', 'r') as fl:
fl = json.load(fl)
print(fl)
self.x = fl['user']
for i in self.x:
self.count += 1
Todo(text=i['text'], frame=self.frame, count=self.count, text2=i['txt'])
class Todo():
def __init__(self, text, frame, count, text2):
self.text = text
self.text2 = text2
self.count = count
self.frame = frame
self.out = self.create()
self.out.place(x=10, y=((40*self.count) + (30*self.count) + 10))
def create(self):
self.foma = tk.Frame(self.frame, borderwidth=1, relief='solid', height=60, width=400)
self.label = tk.Label(self.foma, text=self.text)
self.label.place(x=5, y=5)
self.bt = tk.Button(self.foma, text='''______
______
______''', command=lambda : HelpMenu(self.foma, self.text2))
self.bt.place(x=358, y=1)
return self.foma
if __name__ == '__main__':
root = App()
root.geometry('640x500')
root.title("TooList")
root.mainloop()
При запуске вылазит вот такая ошибка:
Traceback (most recent call last):
File "e:\Программы\ToDoList\main.py", line 146, in
root = App()
^^^^^
File "e:\Программы\ToDoList\main.py", line 91, in __init__
self.todomag()
File "e:\Программы\ToDoList\main.py", line 115, in todomag
Todo(text=i['text'], frame=self.frame, count=self.count, text2=i['txt'])
File "e:\Программы\ToDoList\main.py", line 126, in __init__
self.out = self.create()
^^^^^^^^^^^^^
File "e:\Программы\ToDoList\main.py", line 131, in create
self.foma = tk.Frame(self.frame, borderwidth=1, relief='solid', height=60, width=400)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Acer\AppData\Local\Programs\Python\Python312\Lib\tkinter\__init__.py", line 3208, in __init__
Widget.__init__(self, master, 'frame', cnf, {}, extra)
File "C:\Users\Acer\AppData\Local\Programs\Python\Python312\Lib\tkinter\__init__.py", line 2642, in __init__
self._setup(master, cnf)
File "C:\Users\Acer\AppData\Local\Programs\Python\Python312\Lib\tkinter\__init__.py", line 2611, in _setup
self.tk = master.tk
^^^^^^^^^
AttributeError: 'function' object has no attribute 'tk'