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
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- Python | Add image on a Tkinter button
- Python | Creating a button in tkinter
- Open a new Window with a button in Python-Tkinter
- Python Tkinter | Create LabelFrame and add widgets to it
- Tkinter | Adding style to the input text using ttk.Entry widget
- PyQt5 – How to add action to a button ?
- Add image button using .kv file in kivy
- PyQt5 – Add image icon on a Push button
- PyQt5 - How to add icon to Radio Button ?
- PyQt5 QSpinBox - Add border to the down button
- wxPython - Add Image in Button
- Python GUI - tkinter
- Python | askopenfile() function in Tkinter
- Python | Binding function in Tkinter
- Color game using Tkinter in Python
- Python | Message Encode-Decode using Tkinter
- Python - Tkinter askquestion Dialog
- Python | Simple registration form using Tkinter
- Python | Simple GUI calculator using Tkinter
- Python | Distance-time GUI calculator using 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 firstname.lastname@example.org. 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.