main
Robert 6 months ago
commit 41f1a72190
  1. 2
      .gitignore
  2. 9
      LICENSE
  3. 11
      calc.desktop
  4. 57
      calc.py
  5. 38
      calc.spec
  6. BIN
      dist/calc

2
.gitignore vendored

@ -0,0 +1,2 @@
/venv/
/build/

@ -0,0 +1,9 @@
MIT License
Copyright (c) <2025> <Robert Strutts>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

@ -0,0 +1,11 @@
[Desktop Entry]
Version=1.0
Name=Bobs Calculator
Comment=Bobs Calculator
GenericName=Calculator
Keywords=calc,calculator
Exec=/usr/local/bin/calc
Terminal=false
Type=Application
Icon=/usr/share/icons/gnome/32x32/apps/calc.png
Categories=GNOME;GTK;

@ -0,0 +1,57 @@
import tkinter as tk
from tkinter import messagebox
def on_click(event):
text = event.widget.cget("text")
if text == "=":
calculate_result()
elif text == "C":
clear_entry()
else:
entry_var.set(entry_var.get() + text)
def calculate_result(event=None):
try:
result = eval(str(entry.get()))
result = round(float(result), 2) # Format to 2 decimal places
entry_var.set(f"{result:.2f}")
except Exception as e:
messagebox.showerror("Error", f"Invalid Expression: {e}")
def clear_entry(event=None):
entry_var.set("")
return "break" # Prevents default behavior of inserting 'c' or 'C'
# Main window
root = tk.Tk()
root.title("Bobs Calc")
root.geometry("215x250")
entry_var = tk.StringVar()
entry = tk.Entry(root, textvariable=entry_var, font="Arial 20")
entry.pack(fill=tk.BOTH, ipadx=8, pady=10, padx=10)
entry.focus_set() # Set focus to the entry widget
entry.bind("<Return>", calculate_result) # Bind Enter key to calculate_result
entry.bind("<KP_Enter>", calculate_result) # Bind NumPad Enter key
entry.bind("<c>", clear_entry) # Bind 'c' key to clear_entry
entry.bind("<C>", clear_entry) # Bind 'C' key to clear_entry
button_frame = tk.Frame(root)
button_frame.pack()
buttons = [
["7", "8", "9", "/"],
["4", "5", "6", "*"],
["1", "2", "3", "-"],
["C", "0", "=", "+"]
]
for row in buttons:
row_frame = tk.Frame(button_frame)
row_frame.pack(expand=True, fill="both")
for btn_text in row:
btn = tk.Button(row_frame, text=btn_text, font="Arial 18", relief=tk.RAISED)
btn.pack(side=tk.LEFT, expand=True, fill="both")
btn.bind("<Button-1>", on_click)
root.mainloop()

@ -0,0 +1,38 @@
# -*- mode: python ; coding: utf-8 -*-
a = Analysis(
['calc.py'],
pathex=[],
binaries=[],
datas=[],
hiddenimports=[],
hookspath=[],
hooksconfig={},
runtime_hooks=[],
excludes=[],
noarchive=False,
optimize=0,
)
pyz = PYZ(a.pure)
exe = EXE(
pyz,
a.scripts,
a.binaries,
a.datas,
[],
name='calc',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
console=False,
disable_windowed_traceback=False,
argv_emulation=False,
target_arch=None,
codesign_identity=None,
entitlements_file=None,
)

BIN
dist/calc vendored

Binary file not shown.
Loading…
Cancel
Save