import tkinter as tk
from tkinter import messagebox
def calculate_charging_time():
try:
capacity = float(entry_capacity.get())
current = float(entry_current.get())
if current <= 0:
messagebox.showerror("Ошибка", "Ток зарядки должен быть больше нуля")
return
# Коэффициент потери энергии (1.2 - 1.4)
efficiency_factor = 1.2
time = (capacity / current) * efficiency_factor
hours = int(time)
minutes = int((time - hours) * 60)
label_result.config(text=f"Время зарядки: {hours} ч. {minutes} мин.")
except ValueError:
messagebox.showerror("Ошибка", "Пожалуйста, введите корректные числа")
# Создание окна
root = tk.Tk()
root.title("Калькулятор зарядки")
root.geometry("300x250")
# Поля ввода
tk.Label(root, text="Емкость аккумулятора (мАч/Ач):").pack(pady=5)
entry_capacity = tk.Entry(root)
entry_capacity.pack()
tk.Label(root, text="Зарядный ток (мА/А):").pack(pady=5)
entry_current = tk.Entry(root)
entry_current.pack()
# Кнопка расчета
btn_calc = tk.Button(root, text="Рассчитать", command=calculate_charging_time)
btn_calc.pack(pady=15)
# Результат
label_result = tk.Label(root, text="Время зарядки: --", font=("Arial", 10, "bold"))
label_result.pack()
root.mainloop()