import tkinter as tk
def calculate():
elements = []
ratios = []
for i in range(5):
element = float(entry_fields[i].get())
ratio = float(entry_ratios[i].get())
elements.append(element)
ratios.append(ratio)
multiplied_elements = [element * ratio / 100 for element, ratio in zip(elements, ratios)]
sum_of_elements = sum(multiplied_elements)
result_text.set("نتائج الضرب:\n{}\nمجموع الأعداد: {:.2f}".format(
"\n".join(["{}: {:.2f}".format(element_names[i], multiplied_elements[i]) for i in range(5)]),
sum_of_elements
))
# إعداد واجهة النافذة
window = tk.Tk()
window.title("حساب الضرب والمجموع")
# تعيين حجم النافذة
window_width = 400
window_height = 300
screen_width = window.winfo_screenwidth()
screen_height = window.winfo_screenheight()
x_position = int((screen_width / 2) - (window_width / 2))
y_position = int((screen_height / 2) - (window_height / 2))
window.geometry(f"{window_width}x{window_height}+{x_position}+{y_position}")
# إنشاء عناصر واجهة المستخدم
entry_fields = []
entry_ratios = []
element_names = ["عنصر 1", "عنصر 2", "عنصر 3", "عنصر 4", "عنصر 5"]
ratio_names = ["نسبة 1", "نسبة 2", "نسبة 3", "نسبة 4", "نسبة 5"]
for i in range(5):
label = tk.Label(window, text="{}: ".format(element_names[i]))
label.grid(row=i, column=0)
entry = tk.Entry(window)
entry.grid(row=i, column=1)
entry_fields.append(entry)
label_ratio = tk.Label(window, text="{}: ".format(ratio_names[i]))
label_ratio.grid(row=i, column=2)
entry_ratio = tk.Entry(window)
entry_ratio.grid(row=i, column=3)
entry_ratios.append(entry_ratio)
button_calculate = tk.Button(window, text="احسب", command=calculate)
button_calculate.grid(row=6, column=0, columnspan=4)
result_text = tk.StringVar()
label_result = tk.Label(window, textvariable=result_text)
label_result.grid(row=7, column=0, columnspan=4)
# تشغيل الواجهة الرسومية
window.mainloop()