Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to make tkinter look modern

# 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 :: lable on graph in matplotlib 
Python :: remove from list if not maches in list 
Python :: time.sleep() python 
Python :: add 1 to all columns in numpy array 
Python :: two groupby pandas 
Python :: list pop python 
Python :: selenium save page as image 
Python :: python convert strings to chunks 
Python :: how to split string by list of indexes python 
Python :: python get number of arguments of a function 
Python :: pandas count number of repetitions of each diferent value 
Python :: django create view 
Python :: similarity index in python 
Python :: big comments python 
Python :: collections counter sort by value 
Python :: how to find a prime number 
Python :: how to use assert in python 
Python :: plotly coordinates mapping 
Python :: upload file to aws 
Python :: models in django 
Python :: pronic number program in python 
Python :: python how to insert values into string 
Python :: manage python environment in jupyterlab 
Python :: turtle graphics documentation|pensize 
Python :: xml depth python 
Python :: python decorator 
Python :: python get total gpu memory 
Python :: csv read python 
Python :: matrix diagonal sum leetcode in java 
Python :: python multiply string 
ADD CONTENT
Topic
Content
Source link
Name
3+3 =