Created
January 7, 2023 19:27
-
-
Save Alexandro1112/cfa8ff732e38ad637e726b931458b1d0 to your computer and use it in GitHub Desktop.
This file contains 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 | |
import customtkinter as tks | |
root = tk.Tk() | |
root.geometry('300x200') | |
root['bg'] = 'lightblue' | |
symbols = ['*', '/', '+', '-', '7', '8', '9', '0', '4', '5', '6', 'C', '1', '2', '3', '='] | |
c = 0 | |
r = 1 | |
def func(x): | |
if x == "C": | |
text1.configure(text='') | |
elif x == '=': | |
text1['text'] = eval(text1['text']) | |
else: | |
text1['text'] += x | |
for j in range(4): | |
root.columnconfigure(weight=1, index=j, minsize=4) | |
for b in range(5): | |
root.rowconfigure(index=b, weight=1, minsize=4) | |
text1 = tk.Label(root, text='', bg='lightblue') | |
text1.grid(row=0, column=0, columnspan=4) | |
for i in symbols: | |
btn = tks.CTkButton(root, text=i, command=lambda x=i: func(x)).grid(row=r, column=c, sticky='nsew') | |
c += 1 | |
if c > 3: | |
r += 1 | |
c = 0 | |
root.mainloop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment