Adding Themed Style to Python application
This post is addition to my FREE e-book: Build simple Library Manager with Python and Tkinter.
There are many things you can do to improve your python Tkinter application, either by adding new useful features or by making look and feel more user friendly.
When it comes to Tkinter GUI library, there is widespread opinion that it looks outdated and ugly when compared to other platforms like Kivy or PyQT. However, not many people have used themed styles for Tkinter and those styles give python application really modern look. You can check all available themes on Github: https://github.com/TkinterEP/ttkthemes
To install themes open your command prompt and execute:
pip install ttkthemes
You will have to add few lines and change few lines in your application.
First, you need to import newly installed library like this:
from ttkthemes import ThemedStyle
Next, in both add_book_dialog and edit_book_dialog functions, just after creating Tk window with self.tl=Tk() add style like this:
#Setting theme
style = ThemedStyle(self.tl)
style.set_theme(“plastik”)
You can experiment here with other styles like: Aquativo, Arc, Black, Blue, Breeze, Clearlooks, Elegance, Keramik, Yaru and others, see docs for full info.
Also you will have to remove styling parameters for buttons. In add_book_dialog function, instead of line upbtn = Button(...) add new line:
upbtn = ttk.Button (self.tl, text=’Add new book’, command = lambda:self.add_book(ne1, ne2, ne3, ne4))
Please also in edit_book_dialog do the same for Enter details and Delete book buttons: instead of Button add ttk.Button and delete bg and fg parameters.
Finally at the bottom of the code there is line to create root window: root = Tk(). Just below this line add code to apply plastik style to root window also:
#Setting style
style = ThemedStyle(root)
style.set_theme(“plastik”)
Style is applied and your application should look as image below.


Post a Comment
0 Comments
Thanks for sharing your thoughts !