Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to make tkinter look better

# 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 :: matplotlib legend number columns 
Python :: change month name in python 
Python :: pass arguments with apply 
Python :: terminal commands for install python on cpanel 
Python :: python timedelta years 
Python :: matlab filter in python 
Python :: noise reduction filter images python 
Python :: spark.read.load 
Python :: length of a string python 
Python :: generate random list and find max in list python 
Python :: indexes meta django 
Python :: python escape character example 
Python :: #finding the similarity among two sets 
Python :: Python list files only in given directory 
Python :: gaierror at /members/register [Errno 11001] getaddrinfo failed 
Python :: run python command 
Python :: python list of dictionaries to list 
Python :: make_response is not defined django 
Python :: upload file to s3 python 
Python :: install ansible with pip 
Python :: how to show bar loading in python in cmd 
Python :: axis labels python 
Python :: python module location 
Python :: beautifulsoup getting data from a website 
Python :: optimize images using pillow 
Python :: python array join 
Python :: expand alphabets in python 
Python :: python capitalize the entire string 
Python :: matrix diagonal sum python 
Python :: how to union value without the same value in numpy 
ADD CONTENT
Topic
Content
Source link
Name
3+6 =