Skip to content
Tcl Source Code View Ticket
Login

View Ticket

Tcl/Tk, Tkinter and X11 system colors

Closed3f7eca5475a5ead14708b914b20f8528c1b2f293Created 4 years agoUpdated 42 days ago
Descriptionplain2022-08-25 21:12:38
Hello. I'm using several Tkinter apps under Arch Linux with i3 window manager.  All Tk applications use black background color by default which defined in X11 .Xresourses file.
Is there any other way to override this behaviour except monkey patching every python app or changing system colors?
Can I configure Tcl/Tk systemwide somehow, for all Tkinter applications?
serhiy.storchakawiki2026-09-20 10:59:11

Tk loads the X resources (the RESOURCE_MANAGER property set by xrdb, or ~/.Xdefaults if it is not set) into its option database, so a wildcard entry such as *background: black applies to every Tk widget, as it does to every other X application which honours resources. It is not specific to Tkinter.

The usual fix is to restrict such entries in .Xresources to the applications they are meant for, e.g. URxvt*background or XTerm*background, instead of *background.

If you cannot change them, a more specific pattern for the Tk application class wins over the wildcard. Tkinter applications have the class Tk by default (the className argument of tkinter.Tk), so this in .Xresources restores the defaults for all of them:

Tk*background: #d9d9d9
Tk*foreground: black
Tk*Entry.background: white
Tk*Text.background: white
Tk*Listbox.background: white
(a wish script has the class Wish, other scripts the capitalized script name). There is no separate system-wide Tk configuration file; on X11 the resource database is that mechanism.

serhiy.storchaka Ticket [3f7eca5475]: 3 changes [History diff]2026-10-22 17:19:24
Log in (anonymous is fine) to add a comment.