Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

modern tkinter

# There a library that is based on tkinter which is custom tkinter
# You can see the documentation : https://github.com/TomSchimansky/CustomTkinter/wiki
# it looks really better and modern
# You can see the differnece between the tkinter copy of a program and the customtkinter copy:

# Tkinter copy: https://dl.dropbox.com/s/d95r1pie7dqddn4/python_d3hydWUufF.png?dl=0
# Custom Tkinter copy: https://dl.dropbox.com/s/w1u0mhw0chwfetq/python_MuyDj7n17B.png?dl=0

#tkinter code:
from tkinter import *

def eqFunc():
    try:
        result = eval((equation.get()).replace("×", "*").replace("÷", "/"))
        if result == int(result): result = int(result)
    except: result = "Error"

    equation.delete(0, "end")
    equation.insert(0, result)

buttons = ("1", "2", "3", "+", "4", "5", "6", "-", '7', '8', '9', '×', "(", ")", "=", "÷")

window = Tk()
window.title("Calculator")
window.geometry("525x580")
window.resizable(False, False)

equation = Entry(window, font=("Calibri", 48), width=16)
equation.pack(pady=2)

buttonsGrid = Frame()
buttonsGrid.pack()

fontsize = 40
column = -1
row = 0
for i in buttons:
    column += 1
    if column == 4:
        column = 0
        row += 1

    
    if i == "=":
        ButtonEq = Button(buttonsGrid,  text="=", font=("Calibri", fontsize), width=4, height=1, command=eqFunc)
        ButtonEq.grid(column=2, row=3, pady=5, padx=5)

    else: exec("Button"+i.replace("=", "eq").replace("(", "b1").replace(")", "b2").replace("+", "P").replace("-", "Min").replace("×", "Mul").replace("÷", "D")+" = Button(buttonsGrid,  text='"+i+"', font=('Calibri', fontsize), width=4, height=1, command=lambda: equation.insert(equation.index('insert'), '"+i+"')) 
Button"+i.replace("=", "eq").replace("(", "b1").replace(")", "b2").replace("+", "P").replace("-", "Min").replace("×", "Mul").replace("÷", "D")+".grid(row="+str(row)+", column="+str(column)+", padx=5, pady=5)")

window.mainloop()

#customtkinter code:
from customtkinter import *
set_appearance_mode("light")
set_default_color_theme("blue")

def eqFunc():
    try:
        result = eval((equation.get()).replace("×", "*").replace("÷", "/"))
        if result == int(result): result = int(result)
    except: result = "Error"

    equation.delete(0, "end")
    equation.insert(0, result)

buttons = ("1", "2", "3", "+", "4", "5", "6", "-", '7', '8', '9', '×', "(", ")", "=", "÷")

window = CTk()
window.title("Calculator")
window.geometry("500x580")
window.resizable(False, False)

equation = CTkEntry(window, text_font=("Calibri", 48), width=495)
equation.pack(pady=2)

buttonsGrid = CTkFrame()
buttonsGrid.pack()

column = -1
row = 0
for i in buttons:
    column += 1
    if column == 4:
        column = 0
        row += 1

    something = 1.75
    if i == "=":
        ButtonEq = CTkButton(buttonsGrid,  text="=", text_font=("Calibri", int(32*something)), fg_color='#fff', text_color='#000', hover_color='#e3e3e3', width=64*something, height=64*something, command=eqFunc)
        ButtonEq.grid(column=2, row=3, pady=5, padx=5)

    else: exec("Button"+i.replace("=", "eq").replace("(", "b1").replace(")", "b2").replace("+", "P").replace("-", "Min").replace("×", "Mul").replace("÷", "D")+" = CTkButton(buttonsGrid,  text='"+i+"', text_font=('Calibri', int(32*something)), fg_color='#fff', text_color='#000', hover_color='#e3e3e3', width=64*something, height=64*something, command=lambda: equation.insert(equation.cursorIndex(), '"+i+"')) 
Button"+i.replace("=", "eq").replace("(", "b1").replace(")", "b2").replace("+", "P").replace("-", "Min").replace("×", "Mul").replace("÷", "D")+".grid(row="+str(row)+", column="+str(column)+", padx=5, pady=5)")

window.mainloop()
Comment

PREVIOUS NEXT
Code Example
Python :: Python Datetime Get year, month, hour, minute, and timestamp 
Python :: how to get SITE_ID in django....shell 
Python :: save image to file from URL 
Python :: Python random integer number between min, max 
Python :: matplotlib plot in second axis 
Python :: Yahoo! Finance pyhton 
Python :: new column with addition of other columns 
Python :: how to change value of categorical variable in python 
Python :: python __repr__ 
Python :: appending objects to a list contained in a dictionary python 
Python :: save seaborn lmplot 
Python :: strip whitespace python 
Python :: similarity imdex in python 
Python :: python dataframe save 
Python :: scree plot sklearn 
Python :: python call function in class 
Python :: assert integer python 
Python :: python program to find the sum of fibonacci series 
Python :: upload file to s3 
Python :: python delete key dictionary 
Python :: how to print out even index in python 
Python :: matplotlib axis labels 
Python :: load png to python 
Python :: turtle graphics documentation 
Python :: add horizontal line to plotly scatter 
Python :: python list contains 
Python :: f readlines python not working 
Python :: python lambda key sort 
Python :: leetcode matrix diagonal sum in python 
Python :: django email change sender name 
ADD CONTENT
Topic
Content
Source link
Name
7+1 =