Last active
May 30, 2026 04:18
-
-
Save smkplus/2fb2a6b3af2f5458b71c67e0229dd557 to your computer and use it in GitHub Desktop.
محاسبه قیمت پرینت سه بعدی
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import tkinter as tk | |
| from tkinter import messagebox | |
| from datetime import datetime | |
| def calculate_cost(): | |
| try: | |
| printer_hours = float(entry_printer_hours.get()) | |
| machine_rate = float(entry_machine_rate.get()) | |
| filament_used = float(entry_filament_used.get()) | |
| filament_price = float(entry_filament_price.get()) | |
| filament_markup = float(entry_filament_markup.get()) | |
| error_margin = float(entry_error_margin.get()) | |
| shipping_cost = float(entry_shipping_cost.get()) | |
| # محاسبات | |
| machine_cost = printer_hours * machine_rate | |
| base_filament_cost = filament_used * filament_price | |
| filament_cost = base_filament_cost * filament_markup | |
| subtotal = machine_cost + filament_cost | |
| total_after_margin = subtotal * error_margin | |
| total_cost = total_after_margin + shipping_cost | |
| now = datetime.now().strftime("%Y-%m-%d %H:%M:%S") | |
| invoice_text = ( | |
| f"فاکتور محاسبه هزینه پرینت سهبعدی\n" | |
| f"تاریخ: {now}\n" | |
| f"{'=' * 40}\n\n" | |
| f"1) هزینه دستگاه\n" | |
| f" زمان پرینت: {printer_hours:.3f} ساعت\n" | |
| f" نرخ دستگاه: {machine_rate:,.0f} تومان / ساعت\n" | |
| f" فرمول: {printer_hours:.3f} × {machine_rate:,.0f}\n" | |
| f" هزینه دستگاه: {machine_cost:,.0f} تومان\n\n" | |
| f"2) هزینه فیلامنت\n" | |
| f" مقدار مصرف: {filament_used:.2f} گرم\n" | |
| f" قیمت هر گرم: {filament_price:,.0f} تومان\n" | |
| f" هزینه خام فیلامنت: {base_filament_cost:,.0f} تومان\n" | |
| f" ضریب سود فیلامنت: {filament_markup}\n" | |
| f" هزینه نهایی فیلامنت: {filament_cost:,.0f} تومان\n\n" | |
| f"3) جمع قبل از ضریب خطا\n" | |
| f" فرمول: {machine_cost:,.0f} + {filament_cost:,.0f}\n" | |
| f" جمع جزء: {subtotal:,.0f} تومان\n\n" | |
| f"4) ضریب خطا / ریسک / پرت\n" | |
| f" ضریب خطا: {error_margin}\n" | |
| f" فرمول: {subtotal:,.0f} × {error_margin}\n" | |
| f" قیمت پس از ضریب خطا: {total_after_margin:,.0f} تومان\n\n" | |
| f"5) هزینه ارسال\n" | |
| f" هزینه ارسال: {shipping_cost:,.0f} تومان\n\n" | |
| f"6) جمع نهایی\n" | |
| f" فرمول: {total_after_margin:,.0f} + {shipping_cost:,.0f}\n" | |
| f" مبلغ نهایی: {total_cost:,.0f} تومان\n\n" | |
| f"{'=' * 40}\n" | |
| f"مبلغ قابل پرداخت: {total_cost:,.0f} تومان" | |
| ) | |
| result_text.set(invoice_text) | |
| except ValueError: | |
| messagebox.showerror( | |
| "خطا", | |
| "لطفاً همه فیلدها را بهصورت عددی وارد کنید." | |
| ) | |
| root = tk.Tk() | |
| root.title("محاسبه هزینه پرینت سهبعدی") | |
| root.geometry("750x800") | |
| title = tk.Label( | |
| root, | |
| text="محاسبه قیمت پرینت سهبعدی", | |
| font=("Arial", 16, "bold") | |
| ) | |
| title.pack(pady=10) | |
| frame = tk.Frame(root) | |
| frame.pack(pady=10, fill="x", padx=20) | |
| def add_field(label_text, default_value=""): | |
| row = tk.Frame(frame) | |
| row.pack(fill="x", pady=5) | |
| label = tk.Label( | |
| row, | |
| text=label_text, | |
| width=35, | |
| anchor="w", | |
| font=("Arial", 10) | |
| ) | |
| label.pack(side="left") | |
| entry = tk.Entry(row, font=("Arial", 10)) | |
| entry.insert(0, default_value) | |
| entry.pack(side="right", expand=True, fill="x") | |
| return entry | |
| # ورودیها | |
| entry_printer_hours = add_field( | |
| "Printer Hours / زمان پرینت به ساعت", | |
| "1.783" | |
| ) | |
| entry_machine_rate = add_field( | |
| "Machine Rate / نرخ ساعتی دستگاه", | |
| "100000" | |
| ) | |
| entry_filament_used = add_field( | |
| "Filament Used / فیلامنت مصرفی به گرم", | |
| "30.79" | |
| ) | |
| entry_filament_price = add_field( | |
| "Filament Price / قیمت هر گرم فیلامنت", | |
| "3000" | |
| ) | |
| entry_filament_markup = add_field( | |
| "Filament Markup / ضریب سود فیلامنت", | |
| "1.3" | |
| ) | |
| entry_error_margin = add_field( | |
| "Error Margin / ضریب خطا", | |
| "1.1" | |
| ) | |
| entry_shipping_cost = add_field( | |
| "Shipping Cost / هزینه ارسال", | |
| "0" | |
| ) | |
| calculate_button = tk.Button( | |
| root, | |
| text="محاسبه و نمایش فاکتور", | |
| command=calculate_cost, | |
| font=("Arial", 12, "bold"), | |
| bg="#4CAF50", | |
| fg="white" | |
| ) | |
| calculate_button.pack(pady=15) | |
| result_text = tk.StringVar() | |
| result_label = tk.Label( | |
| root, | |
| textvariable=result_text, | |
| font=("Courier New", 10), | |
| justify="left", | |
| anchor="nw", | |
| bg="#f7f7f7", | |
| padx=15, | |
| pady=15, | |
| bd=1, | |
| relief="solid" | |
| ) | |
| result_label.pack( | |
| fill="both", | |
| expand=True, | |
| padx=20, | |
| pady=10 | |
| ) | |
| root.mainloop() |
smkplus
commented
May 30, 2026
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment