class RecipeWindow(tk.Toplevel):
def __init__(self, parent, title, recipe_name=None):
super().__init__(parent.root)
self.parent = parent
self.recipe_name = recipe_name
self.title(title)
self.create_widgets()
if self.recipe_name:
self.load_recipe_data()
def create_widgets(self):
tk.Label(self, text="Название Заболевания:").grid(row=0, column=0, padx=10, pady=5, sticky="w")
self.name_entry = tk.Entry(self)
self.name_entry.grid(row=0, column=1, padx=10, pady=5, sticky="ew")
tk.Label(self, text="Симптомы:").grid(row=1, column=0, padx=10, pady=5, sticky="w")
self.ingredient_entry = tk.Entry(self)
self.ingredient_entry.grid(row=1, column=1, padx=10, pady=5, sticky="ew")
tk.Label(self, text="Длительность:").grid(row=1, column=2, padx=10, pady=5, sticky="w")
self.quantity_spinbox = tk.Spinbox(self, from_=1, to=100)
self.quantity_spinbox.grid(row=1, column=2, padx=10, pady=5, sticky="ew")
self.add_ingredient_button = tk.Button(self, text="Добавить симптом", command=self.add_ingredient)
self.add_ingredient_button.grid(row=1, column=4, padx=10, pady=5, sticky="ew")
self.ingredients_listbox = tk.Listbox(self, height=5)
self.ingredients_listbox.grid(row=2, column=1, padx=10, pady=5, sticky="ew", columnspan=3)
self.scrollbar = tk.Scrollbar(self, orient=tk.VERTICAL, command=self.ingredients_listbox.yview)
self.ingredients_listbox.config(yscrollcommand=self.scrollbar.set)
self.scrollbar.grid(row=2, column=4, sticky="ns")
self.delete_ingredient_button = tk.Button(self, text="Удалить симптом", command=self.delete_ingredient)
self.delete_ingredient_button.grid(row=2, column=5, padx=10, pady=5, sticky="ew")
tk.Label(self, text="Тяжесть болезни:").grid(row=3, column=0, padx=10, pady=5, sticky="w")
self.cake_type_entry = tk.Entry(self)
self.cake_type_entry.grid(row=3, column=1, padx=10, pady=5, sticky="ew")
tk.Label(self, text="Длительность лечения:").grid(row=4, column=0, padx=10, pady=5, sticky="w")
self.steps_entry = tk.Entry(self)
self.steps_entry.grid(row=4, column=1, padx=10, pady=5, sticky="ew")
self.browse_image_button = tk.Button(self, text="Выбрать", command=self.browse_image)
self.browse_image_button.grid(row=5, column=2, padx=10, pady=5, sticky="ew")
tk.Label(self, text="Min.Стоимость лечения:").grid(row=6, column=0, padx=10, pady=5, sticky="w")
self.cost_entry = tk.Entry(self)
self.cost_entry.grid(row=6, column=1, padx=10, pady=5, sticky="ew")
tk.Label(self, text="Max.Стоимость Лечения:").grid(row=7, column=0, padx=10, pady=5, sticky="w")
self.selling_price_entry = tk.Entry(self)
self.selling_price_entry.grid(row=7, column=1, padx=10, pady=5, sticky="ew")
self.save_button = tk.Button(self, text="Сохранить Заболевание", command=self.save_recipe)
self.save_button.grid(row=8, column=0, columnspan=2, padx=10, pady=5, sticky="ew")
self.grid_columnconfigure(1, weight=1)
def add_ingredient(self):
ingredient = self.ingredient_entry.get()
quantity = self.quantity_spinbox.get()
if ingredient and quantity:
self.ingredients_listbox.insert(tk.END, f"{ingredient} - {quantity}")
self.ingredient_entry.delete(0, tk.END)
self.quantity_spinbox.delete(0, tk.END)
def delete_ingredient(self):
selected = self.ingredients_listbox.curselection()
if selected:
self.ingredients_listbox.delete(selected)
def load_recipe_data(self):
recipe = self.parent.recipes[self.recipe_name]
self.name_entry.insert(0, self.recipe_name)
for ingredient in recipe['ingredients'].split(', '):
self.ingredients_listbox.insert(tk.END, ingredient)
self.steps_entry.insert(0, recipe['steps'])
self.cost_entry.insert(0, recipe['cost'])
self.selling_price_entry.insert(0, recipe['selling_price'])
self.cake_type_entry.insert(0, recipe['cake_type'])
def save_recipe(self):
name = self.name_entry.get()
ingredients = ', '.join(self.ingredients_listbox.get(0, tk.END))
steps = self.steps_entry.get()
image_path = None
cost = self.cost_entry.get()
selling_price = self.selling_price_entry.get()
cake_type = self.cake_type_entry.get()
if name and ingredients and steps and cost and selling_price and cake_type:
self.parent.recipes[name] = {
'ingredients': ingredients,
'steps': steps,
'cost': cost,
'selling_price': selling_price,
'cake_type': cake_type
}
self.parent.save_recipes()
self.parent.update_recipe_list()
self.destroy()
messagebox.showinfo("УРА!", "Заболевание сохранено")
else:
messagebox.showwarning("Не-а!", "Все поля должны быть заполнены данными")
class RecipeDetailsWindow(tk.Toplevel):
def __init__(self, parent, recipe_name, recipe):
super().__init__(parent.root)
self.title(recipe_name)
tk.Label(self, text="Симптомы:").grid(row=0, column=0, padx=10, pady=5, sticky="w")
tk.Label(self, text=recipe['ingredients']).grid(row=0, column=1, padx=10, pady=5, sticky="ew")
tk.Label(self, text="Длительность Лечения:").grid(row=1, column=0, padx=10, pady=5, sticky="w")
tk.Label(self, text=recipe['steps']).grid(row=1, column=1, padx=10, pady=5, sticky="ew")
tk.Label(self, text="Тяжесть Заболевания:").grid(row=2, column=0, padx=10, pady=5, sticky="w")
tk.Label(self, text=recipe['cake_type']).grid(row=2, column=1, padx=10, pady=5, sticky="ew")
tk.Label(self, text="Min.Стоимость Лечения:").grid(row=4, column=0, padx=10, pady=5, sticky="w")
tk.Label(self, text=recipe['cost']).grid(row=4, column=1, padx=10, pady=5, sticky="ew")
tk.Label(self, text="Max.Стоимсоть Лечения:").grid(row=5, column=0, padx=10, pady=5, sticky="w")
tk.Label(self, text=recipe['selling_price']).grid(row=5, column=1, padx=10, pady=5, sticky="ew")
profit = float(recipe['selling_price']) - float(recipe['cost'])
tk.Label(self, text="Разница в стоимости:").grid(row=6, column=0, padx=10, pady=5, sticky="w")
tk.Label(self, text=f"{profit}").grid(row=6, column=1, padx=10, pady=5, sticky="ew")
self.grid_columnconfigure(1, weight=1)
if __name__ == "__main__":
root = tk.Tk()
app = DiseaseApp(root)
root.mainloop()