Tkinter is a Python standard library which is used to create GUI (Graphical User Interface) applications. It is one of the most commonly used package of Python. Tkinter supports both traditional and modern graphics support with the help of
Tk themed widgets. All the widgets that tkinter has also available in tkinter.ttk.
Adding style in a
tkinter.ttk button is little bit creepy because it doesn’t support direct implementation. To add styling in a
ttk.Button we have to first create a object of style class which is available in
We can create ttk.Button by using following steps:
btn = ttk.Button(master, option = value, ...)
ttk.Button options –
command: A function to be called when button is pressed.
text: Text which appears on the Button.
image: Image to be apper on the Button.
style: Style to be used in rendering this button.
To add styling on the
ttk.Button we cannot directly pass the value in the options. Firstly, we have to create a Style object which can be created as follows:
style = ttk.Style()
Below code will be adding style to only selected Buttons i.e, only those buttons will get changed in which we will be passing style option.
Only one button will get styled because in the above code we are providing styling only in one Button.
Code #2 Apply style on all the available buttons
Now if you want to change the appearance of the buttons by the movement of mouse i.e, now when we hover mouse over the button it will change it’s color when we press it will change color and so on.
Code #3 Change color on mouse hover
- Python | Add image on a Tkinter button
- Python | Creating a button in tkinter
- Tkinter | Adding style to the input text using ttk.Entry widget
- Python GUI - tkinter
- Python | after method in Tkinter
- Different messages in Tkinter | Python
- RadioButton in Tkinter | Python
- Python | place() method in Tkinter
- minsize() method in Tkinter | Python
- Python | pack() method in Tkinter
- resizable() method in Tkinter | Python
- Python | Menu widget in Tkinter
- Progressbar widget in Tkinter | Python
- Collapsible Pane in Tkinter | Python
- Python | asksaveasfile() function in Tkinter
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.