diff --git a/README.md b/README.md index 20be0c1..dc2d935 100644 --- a/README.md +++ b/README.md @@ -1,30 +1,112 @@ -# Calculator (Tkinter) +# Stylish Dark Purple Calculator Built with Python and Tkinter 🌌 -This is a stylish and functional calculator app built with Python’s Tkinter library. -It features a **custom dark-violet theme**, **memory functions**, and a sleek modern layout inspired by monochrome UI palettes. +![Calculator](https://img.shields.io/badge/Download%20Latest%20Release-Click%20Here-brightgreen?style=flat&logo=github) -![Calculator Screenshot] -!(![alt text](image.png)) +Welcome to the **Calculator-** repository! This project features a custom-built calculator using Python and Tkinter. The design boasts a dark purple theme inspired by the beauty of galaxies. With full arithmetic functionality and a clean user interface, this calculator is perfect for anyone looking to learn GUI development in Python. +## Table of Contents ---- +- [Features](#features) +- [Installation](#installation) +- [Usage](#usage) +- [Functionality](#functionality) +- [Contributing](#contributing) +- [Topics](#topics) +- [License](#license) -## 🎨 Features +## Features -- 🌌 Gorgeous dark purple & lavender aesthetic -- 🧠 Memory buttons: `M+`, `MR`, `MC` -- ➕ All standard math operations: `+`, `-`, `×`, `÷`, `%`, `.`, `00` -- 🧹 Clear (`C`) and backspace (`CE`) -- 🖥️ Clean custom layout with large buttons -- 💯 Built using pure Python – no extra libraries +- **Aesthetic Design**: The dark purple theme offers a modern look, making calculations visually appealing. +- **Full Arithmetic Functionality**: Perform basic math operations such as addition, subtraction, multiplication, and division. +- **Memory Functions**: Use memory buttons (M+, MR, MC) to store and recall values. +- **Clear and Off/On Controls**: Easily clear the current entry or turn the calculator on and off. +- **User-Friendly Interface**: A clean layout that enhances usability, making it easy for beginners to navigate. ---- +## Installation -## 🚀 How to Run +To get started with the calculator, you need to download the latest release. Visit the [Releases section](https://github.com/xXCupidoXx/Calculator-/releases) to find the necessary files. Download and execute the file to run the application on your desktop. -Make sure you have Python installed (3.x): +### Requirements -```bash -python Calculator.py +- Python 3.x +- Tkinter library (usually included with Python installations) ---- +### Steps + +1. Clone the repository: + ```bash + git clone https://github.com/xXCupidoXx/Calculator-.git + ``` +2. Navigate to the project directory: + ```bash + cd Calculator- + ``` +3. Run the application: + ```bash + python main.py + ``` + +## Usage + +Once you have the application running, you will see a sleek interface. The buttons are clearly labeled, making it easy to perform calculations. + +### How to Use + +- **Basic Operations**: Click the buttons for numbers and operations to perform calculations. +- **Memory Functions**: Use M+ to store a number, MR to recall it, and MC to clear the memory. +- **Clear Entry**: Use the CE button to clear the current entry. +- **Turn Off/On**: Use the OFF/ON button to control the calculator's state. + +## Functionality + +The calculator includes various functionalities to meet your needs: + +- **Arithmetic Operations**: Supports addition (+), subtraction (-), multiplication (*), and division (/). +- **Memory Functions**: + - **M+**: Add the current number to memory. + - **MR**: Recall the number stored in memory. + - **MC**: Clear the memory. +- **Clear Entry**: Clear the current calculation with the CE button. +- **On/Off Control**: Turn the calculator on or off with a simple button. + +## Screenshots + +![Calculator Interface](https://via.placeholder.com/600x400.png?text=Calculator+Interface) + +## Contributing + +We welcome contributions! If you would like to help improve this project, please follow these steps: + +1. Fork the repository. +2. Create a new branch for your feature or bug fix. +3. Make your changes and commit them. +4. Push your branch to your forked repository. +5. Create a pull request to the main repository. + +## Topics + +This project covers a variety of topics that may interest you: + +- Aesthetic +- Basic Calculator App +- Beginner Project +- Calculator +- Dark Theme +- Desktop App +- GUI +- Math Operations +- Memory Function +- Pastel Theme +- Python +- Python 3 +- Scientific Calculator +- Tkinter +- UI Design + +## License + +This project is licensed under the MIT License. Feel free to use, modify, and distribute this code as per the license terms. + +For any questions or issues, check the [Releases section](https://github.com/xXCupidoXx/Calculator-/releases) or raise an issue in the repository. + +Thank you for your interest in the **Calculator-** project! \ No newline at end of file diff --git a/calculator.py b/calculator.py index 1b95527..9c041bb 100644 --- a/calculator.py +++ b/calculator.py @@ -1,7 +1,16 @@ import tkinter as tk + +memory = 0 +calculator_on = True + def click(event): + global memory, calculator_on btn_text = event.widget["text"] + + if not calculator_on and btn_text not in ["ON"]: + return # Block input when OFF + if btn_text == "=": try: result = str(eval(entry.get().replace("×", "*").replace("÷", "/"))) @@ -10,20 +19,49 @@ def click(event): except: entry.delete(0, tk.END) entry.insert(tk.END, "Error") + elif btn_text == "C": entry.delete(0, tk.END) + elif btn_text == "CE": - entry.delete(len(entry.get())-1) + current = entry.get() + if current: + entry.delete(len(current)-1, tk.END) + + elif btn_text == "ON": + calculator_on = True + entry.config(state="normal") + entry.delete(0, tk.END) + + elif btn_text == "OFF": + calculator_on = False + entry.config(state="disabled") + + elif btn_text == "M+": + try: + memory = float(entry.get()) + except: + pass + + elif btn_text == "MR": + entry.insert(tk.END, str(memory)) + + elif btn_text == "MC": + memory = 0 + else: entry.insert(tk.END, btn_text) +# UI Setup root = tk.Tk() root.title("Calculator") root.geometry("320x480") -root.config(bg="#0E001E") # Dark purple/navy background +root.config(bg="#0E001E") -entry = tk.Entry(root, font=("Arial", 24), bd=10, relief=tk.FLAT, justify="right", - bg="#48395D", fg="#FEFEFE", insertbackground="white") +entry = tk.Entry( + root, font=("Arial", 24), bd=10, relief=tk.FLAT, justify="right", + bg="#48395D", fg="#FEFEFE", insertbackground="white" +) entry.pack(fill=tk.BOTH, ipadx=8, ipady=15, padx=10, pady=10) buttons = [ @@ -36,10 +74,8 @@ def click(event): ["", "", "", "="] ] - button_colors = { - "=": "#563187", - "+": "#563187", "-": "#563187", "×": "#563187", "÷": "#563187", + "=": "#563187", "+": "#563187", "-": "#563187", "×": "#563187", "÷": "#563187", "ON": "#9F82A0", "OFF": "#9F82A0", "CE": "#310374", "%": "#563187" } @@ -47,6 +83,9 @@ def click(event): frame = tk.Frame(root, bg="#0E001E") frame.pack(expand=True, fill="both", padx=5, pady=2) for btext in row: + if btext == "": + tk.Label(frame, text="", bg="#0E001E").pack(side=tk.LEFT, expand=True, fill="both", padx=3, pady=3) + continue color = button_colors.get(btext, "#310374") btn = tk.Button(frame, text=btext, font=("Arial", 16, "bold"), bg=color, fg="white", relief="flat", bd=3,