@kingslayer

Почему не нажимается кнопка сохранить заболевание?

Здравствуйте, почему не нажимается кнопка сохранить заболевание? И как это исправить
import tkinter as tk
from tkinter import messagebox, filedialog
import os


class DiseaseApp:
    def __init__(self, root):
        self.root = root
        self.root.title("Медицинские услуги.Врач")
        self.root.attributes("-fullscreen", True)
        self.root.config(bg="#efe6dd")
        self.recipes = {}
        self.load_recipes()

        self.create_widgets()

    def create_widgets(self):
        self.canvas = tk.Canvas(self.root)
        self.canvas.place(relx=0.05, rely=0.05, relwidth=0.4, relheight=0.5)

        self.recipe_listbox = tk.Listbox(self.root)
        self.recipe_listbox.place(relx=0.5, rely=0.05, relwidth=0.4, relheight=0.9)
        self.recipe_listbox.bind("<<ListboxSelect>>", self.on_recipe_select)
        self.recipe_listbox.config(fg="#ae6378", bg="#e7b79f",
                                   font=("Arial", 14))

        self.add_button = tk.Button(self.root, text="Добавить заболевание", command=self.add_recipe)
        self.add_button.place(relx=0.05, rely=0.05, relwidth=0.2, relheight=0.1)
        self.add_button = tk.Button(self.root, text="Добавить заболевание", bg="#eab595", fg="black",
                                    command=self.add_recipe)
        self.add_button.place(relx=0.05, rely=0.05, relwidth=0.2, relheight=0.1)

        self.edit_button = tk.Button(self.root, text="Редактировать Заболевание", command=self.edit_recipe)
        self.edit_button.place(relx=0.25, rely=0.05, relwidth=0.2, relheight=0.1)
        self.edit_button = tk.Button(self.root, text="Редактировать Заболевание", bg="#d87f81", fg="black",
                                     command=self.edit_recipe)
        self.edit_button.place(relx=0.25, rely=0.05, relwidth=0.2, relheight=0.1)

        self.delete_button = tk.Button(self.root, text="Удалить Заболевание", command=self.delete_recipe)
        self.delete_button.place(relx=0.25, rely=0.22, relwidth=0.2, relheight=0.1)
        self.delete_button = tk.Button(self.root, text="Удалить Заболевание", bg="#ae6378", fg="black",
                                       command=self.delete_recipe)
        self.delete_button.place(relx=0.25, rely=0.22, relwidth=0.2, relheight=0.1)

        self.open_button = tk.Button(self.root, text="Просмотреть Заболевание", command=self.open_recipe)
        self.open_button.place(relx=0.05, rely=0.22, relwidth=0.2, relheight=0.1)
        self.open_button = tk.Button(self.root, text="Просмотреть Заболевание", bg="#79616f", fg="black",
                                     command=self.open_recipe)
        self.open_button.place(relx=0.05, rely=0.22, relwidth=0.2, relheight=0.1)

        self.exit_button = tk.Button(self.root, text="Покинуть Врача", command=self.root.quit)
        self.exit_button.place(relx=0.148, rely=0.4, relwidth=0.2, relheight=0.1)
        self.exit_button = tk.Button(self.root, text="Покинуть Врача", bg="#7e9680", fg="#100a01", command=self.root.quit)
        self.exit_button.place(relx=0.148, rely=0.4, relwidth=0.2, relheight=0.1)

        self.update_recipe_list()

    def load_recipes(self):
        if os.path.exists("recipes.txt"):
            with open("recipes.txt", "r", encoding="utf-7") as file:
                lines = file.readlines()
                for line in lines:
                    name, ingredients, steps, image_path, cost, selling_price, cake_type = line.strip().split('|')
                    self.recipes[name] = {
                        'ingredients': ingredients,
                        'steps': steps,
                        'image_path': image_path,
                        'cost': cost,
                        'selling_price': selling_price,
                        'cake_type': cake_type
                    }

    def save_recipes(self):
        with open("recipes.txt", "w", encoding="utf-7") as file:
            for name, data in self.recipes.items():
                file.write(
                    f"{name}|{data['ingredients']}|{data['steps']}|{data['image_path']}|{data['cost']}|{data['selling_price']}|{data['cake_type']}\n")

    def update_recipe_list(self):
        self.recipe_listbox.delete(0, tk.END)
        for recipe in self.recipes:
            self.recipe_listbox.insert(tk.END, recipe)



    def add_recipe(self):
        RecipeWindow(self, "Добавить Заболевание")


    def edit_recipe(self):
        selected = self.recipe_listbox.curselection()
        if selected:
            recipe_name = self.recipe_listbox.get(selected)
            RecipeWindow(self, "Редактировать Заболевание", recipe_name)

    def delete_recipe(self):
        selected = self.recipe_listbox.curselection()
        if selected:
            recipe_name = self.recipe_listbox.get(selected)
            del self.recipes[recipe_name]
            self.update_recipe_list()
            self.save_recipes()
            self.update_image_panel()
            messagebox.showinfo("Успех", "Заболевание удалено")

    def open_recipe(self):
        selected = self.recipe_listbox.curselection()
        if selected:
            recipe_name = self.recipe_listbox.get(selected)
            recipe = self.recipes[recipe_name]
            RecipeDetailsWindow(self, recipe_name, recipe)

    def on_recipe_select(self, event):
        selected = self.recipe_listbox.curselection()
        if selected:
            recipe_name = self.recipe_listbox.get(selected)
            image_path = self.recipes[recipe_name]['image_path']
            self.update_image_panel(image_path)
  • Вопрос задан
  • 127 просмотров
Пригласить эксперта
Ответы на вопрос 1
HemulGM
@HemulGM Куратор тега Python
Delphi Developer, сис. админ
Покупаешь магический шар и спрашиваешь у него. Все программисты так делают. И не вздумай гуглить, что такое "отладка".
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы