top of page

Stylizing Your Tkinter Gui Programs For Python 3.9

  • Writer: Brian Clark
    Brian Clark
  • Apr 21, 2022
  • 1 min read

Updated: Jul 10, 2022

The new version of the number adder looks a lot better with a few additions.



Here is the source code :

''' 
Author: Brian Clark 

Sources:

'''
import tkinter
import customtkinter

window = tkinter.Tk()
window.title("Number Adder V1.2")

# Modes: system (default), light, dark
customtkinter.set_appearance_mode("dark")
# Themes: blue (default), dark-blue, green
customtkinter.set_default_color_theme("blue")


def addNumbers():
    res = int(e1.get())+int(e2.get())
    myText.set(res)
    e3.insert(3, res)


master = customtkinter.CTk()
# create CTk window like you do with the Tk window
master.geometry("400x240")
master.title("Number Add V1.2")
# note : add customtkinter.CTK____ to modify the current label | Entry | Widget 
myText = tkinter.StringVar()

customtkinter.CTkLabel(master, text="First").grid(row=0, sticky=tkinter.W)
customtkinter.CTkLabel(master, text="Second").grid(row=1, sticky=tkinter.W)
customtkinter.CTkLabel(master, text="Result:").grid(row=3, sticky=tkinter.W)

result = customtkinter.CTkLabel(master, text="", textvariable=myText).grid(
    row=3, column=1, sticky=tkinter.W)

e1 = customtkinter.CTkEntry(master)
e2 = customtkinter.CTkEntry(master)
e3 = customtkinter.CTkEntry(master)

e1.grid(row=0, column=1)
e2.grid(row=1, column=1)
e3.grid(row=3, column=1)

b = customtkinter.CTkButton(master=master, text="Calculate", command=addNumbers)
b.grid(row=4, column=1, columnspan=2)

# I belive not adding the "master" selector cuased the error 
master.mainloop()


'''

#Reference 

import tkinter
import customtkinter

customtkinter.set_appearance_mode("System")  # Modes: system (default), light, dark
customtkinter.set_default_color_theme("blue")  # Themes: blue (default), dark-blue, green

root_tk = customtkinter.CTk()  # create CTk window like you do with the Tk window
root_tk.geometry("400x240")

def button_function():
    print("button pressed")

# Use CTkButton instead of tkinter Button
button = customtkinter.CTkButton(master=root_tk, text="CTkButton", command=button_function)
button.place(relx=0.5, rely=0.5, anchor=tkinter.CENTER)

root_tk.mainloop()



'''

References:

Tom S. (April 4, 2022) CustomTkinter UI-Library. Github




Comments


bottom of page