Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I change the overall theme of a tkinter application?

I want to change the theme of my tkinter application to clam.

What is the code and where do I put it? I have tried:

from tkinter import *
from tkinter.ttk import *
s=ttk.Style()
s.theme_use('clam')
like image 664
InsuranceCompanyThatCares Avatar asked Jun 23 '14 13:06

InsuranceCompanyThatCares


People also ask

What is config () in tkinter?

config() method. Syntax: Label.config(text) Parameter: text– The text to display in the label. This method is used for performing an overwriting over label widget.

What is the difference between tkinter and tkinter TTK?

Tkinter widgets are used to add Buttons, Labels, Text, ScrollBar, etc., however, tkinter. ttk supports a variety of widgets as compared to tkinter widgets. Tkinter. ttk doesn't support Place, Pack() and Grid(), thus it is recommended to use tkinter widget with ttk.

How do I change the background in TTK?

Tkinter supports ttk widget which is used to change the style and properties of any widget in a tkinter application. We can set the background color, foreground color, and other attributes of the Combobox widget by visiting the configure function in ttk and passing 'TCombobox' as the first parameter.


2 Answers

To change the theme, call .theme_use() with the theme's name as the argument.

From https://infohost.nmt.edu/tcc/help/pubs/tkinter/web/ttk-theme-layer.html

A number of operations related to themes require that you have available an instance of the ttk.Style() class (in the Python sense of class). For example, to obtain a list of the available themes in your installation:

>>> import ttk  # import tkinter.ttk as ttk for Python 3
>>> s=ttk.Style()
>>> s.theme_names()
('clam', 'alt', 'default', 'classic')

The .theme_names() method returns a tuple containing the names of the available styles. The 'classic' theme gives you the original, pre-ttk appearance.

To determine which theme you get by default, use the .theme_use() method with no arguments. To change the current theme, call this same method with the desired theme name as the argument:

>>> s.theme_use()
'default'
>>> s.theme_use('alt')
>>> s.theme_use()
'alt'
like image 130
blakev Avatar answered Sep 30 '22 12:09

blakev


>>> from tkinter import ttk

>>> s=ttk.Style()

>>> s.theme_names() """======== if you are under win 8.1 you must see ..
 ('winnative', 'clam', 'alt', 'default', 'classic', 'vista', 'xpnative') you can use for example 'clam' ===== """

>>> s.theme_use('clam')
like image 20
8achir Avatar answered Sep 30 '22 14:09

8achir