Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Python GUI Programming with Tkinter

You're reading from   Python GUI Programming with Tkinter Develop responsive and powerful GUI applications with Tkinter

Arrow left icon
Product type Paperback
Published in May 2018
Publisher Packt
ISBN-13 9781788835886
Length 452 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Alan D. Moore Alan D. Moore
Author Profile Icon Alan D. Moore
Alan D. Moore
Arrow right icon
View More author details
Toc

Table of Contents (17) Chapters Close

Preface 1. Introduction to Tkinter 2. Designing GUI Applications with Tkinter FREE CHAPTER 3. Creating Basic Forms with Tkinter and ttk Widgets 4. Reducing User Error with Validation and Automation 5. Planning for the Expansion of Our Application 6. Creating Menus with Menu and Tkinter Dialogs 7. Navigating Records with Treeview 8. Improving the Look with Styles and Themes 9. Maintaining Cross-Platform Compatibility 10. Creating Automated Tests with unittest 11. Improving Data Storage with SQL 12. Connecting to the Cloud 13. Asynchronous Programming with Thread and Queue 14. Visualizing Data Using the Canvas Widget 15. Packaging with setuptools and cx_Freeze 16. Other Books You May Enjoy

Styling Tkinter widgets


Tkinter has essentially two styling systems: the old Tkinter widgets system, and the newer Ttk system. Since we still need to work with both Tkinter and Ttk widgets, we'll have to look at both systems. Let's take a look first at the older Tkinter system and apply some styling to the Tkinter widgets in our application.

Widget color properties

Basic Tkinter widgets allow you to change two colors: foreground, meaning mainly the text and borders, and background, meaning the rest of the widget. These can be set using the foreground and background arguments, or their aliases fg and bg.

This example shows the use of colors on a Label:

l = tk.Label(text='Hot Dog!', fg='yellow', bg='red')

The values for the colors can be color name strings or CSS-style RGB hex strings.

For example, this code produces the same effect:

l2 = tk.Label(text='Also Hot Dog!',
              foreground='#FFFF00',
              background='#FF0000')

There are over 700 named colors recognized by Tkinter, roughly...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime