Tkinter Ttk is a native library in Tkinter which is used to style the widgets in a Tkinter application. It provides a native GUI interface to all the widgets defined in the application.In order to style the widgets with ttk, we have to import it in the notebook using the command ‘from tkinter import ttk’.
For a particular application, we can change the font properties such as background color, foreground color, font size, font-family, and font style by defining an instance of ttk style object. After initializing the ttk object, we can configure(options) each widget defined in an application.
In this example, we will create a button that can be customized after defining the style object.
#Import the required Libraries from tkinter import * from tkinter import ttk #Create an instance of tkinter frame win = Tk() #Set the geometry of tkinter frame win.geometry("750x270") #Create an instance of Style Object style = ttk.Style() #Create ttk buttons small_button = ttk.Button(win, text="small button", style="small.TButton") small_button.pack(pady=20) big_button = ttk.Button(win, text="big button", style="big.TButton") big_button.pack() #Configure the properties of the Buttons style.configure('big.TButton', font=(None, 20), foreground="blue4") style.configure('small.TButton', font=(None, 7)) win.mainloop()
Running the above code will display a window that will contain two buttons of different sizes and properties.
In the given output, there are two ttk buttons which are having different properties such as font size and color. We can modify the font size by updating the values in the configuration.