Skip to content

Instantly share code, notes, and snippets.

@AnkithAbhayan
Created June 19, 2021 12:39
Show Gist options
  • Save AnkithAbhayan/04e6a130a82c533bf9e915da91c3f946 to your computer and use it in GitHub Desktop.
Save AnkithAbhayan/04e6a130a82c533bf9e915da91c3f946 to your computer and use it in GitHub Desktop.
from tkinter import *
import tkinter.font as tkFont
import json
import webbrowser
import sys
from tkinter import font as tkFont
from tkinter import messagebox
#Written by u/soulcrusher2005
print("Running the script...")
root = Tk()
root.title("u/soulcrusher2005's calculator")
root.geometry("289x520")
root.minsize(289, 427)
my_font = tkFont.Font(family="Fira Code", size=15)
small_font = tkFont.Font(family="Fira Code", size=10)
big_font = tkFont.Font(family="Fira Code", size=20)
field = Entry(root, width=35, borderwidth=2)
field.grid(row=0, column=0, columnspan=3, padx=10, pady=10)
def rickroll():
webbrowser.open("https://www.youtube.com/watch?v=dQw4w9WgXcQ")
root.wm_state('iconic')
messagebox.showinfo("u/soulcrusher2005 says:", "SIKE!!!!")
def button_clickx(number):
current = field.get()
field.delete(0, END)
field.insert(0, str(current) + str(number))
button1 = Button(root, text="1", font=my_font, padx=12, pady=15, command=lambda: button_clickx(1))
button2 = Button(root, text="2", font=my_font, padx=12, pady=15, command=lambda: button_clickx(2))
button3 = Button(root, text="3", font=my_font, padx=12, pady=15, command=lambda: button_clickx(3))
button4 = Button(root, text="4", font=my_font, padx=12, pady=15, command=lambda: button_clickx(4))
button5 = Button(root, text="5", font=my_font, padx=12, pady=15, command=lambda: button_clickx(5))
button6 = Button(root, text="6", font=my_font, padx=12, pady=15, command=lambda: button_clickx(6))
button7 = Button(root, text="7", font=my_font, padx=12, pady=15, command=lambda: button_clickx(7))
button8 = Button(root, text="8", font=my_font, padx=12, pady=15, command=lambda: button_clickx(8))
button9 = Button(root, text="9", font=my_font, padx=12, pady=15, command=lambda: button_clickx(9))
button0 = Button(root, text="0", font=my_font, padx=12, pady=15, command=lambda: button_clickx(0))
button_add = Button(root, text="+", font=big_font, padx=39, pady=20, command=lambda: button_clickx("+"))
button_equal = Button(root, text="=", font=big_font, padx=39, pady=83, command=lambda: rickroll())
button_clear = Button(root, text="clear", font=small_font, padx=32, pady=20)
button_subtract = Button(root, text="-", font=big_font, padx=40, pady=20, command=lambda: button_clickx("-"))
button_multiply = Button(root, text="X", font=big_font, padx=41, pady=20, command=lambda: button_clickx("x"))
button_divide = Button(root, text="/", font=big_font, padx=42, pady=20, command=lambda: button_clickx("/"))
root.rowconfigure((0, 1), weight=1) # make buttons stretch when
root.columnconfigure((0, 2), weight=1) # when window is resized
root.columnconfigure((0, 1), weight=1)
button1.grid(row=3, column=0, sticky="EWNS")
button2.grid(row=3, column=1, sticky="EWNS")
button3.grid(row=3, column=2, sticky="EWNS")
button4.grid(row=2, column=0, sticky="EWNS")
button5.grid(row=2, column=1, sticky="EWNS")
button6.grid(row=2, column=2, sticky="EWNS")
button7.grid(row=1, column=0, sticky="EWNS")
button8.grid(row=1, column=1, sticky="EWNS")
button9.grid(row=1, column=2, sticky="EWNS")
button0.grid(row=4, column=0, sticky="EWNS")
button_clear.grid(row=4, column=1, columnspan=1, sticky="EWNS")
button_add.grid(row=5, column=0, sticky="EWNS")
button_equal.grid(row=4, column=2, rowspan=3, sticky="EWNS")
button_subtract.grid(row=6, column=0, sticky="EWNS")
button_multiply.grid(row=6, column=1, sticky="EWNS")
button_divide.grid(row=5, column=1, sticky="EWNS")
root.mainloop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment