Click event on Tkinter Checkbutton widget does not update the widget visually on the GUI, but it does in code

Viewed 359

Tl;dr: How (Where can we get information) do we troubleshoot Tkinter at this system presentation layer? Surely the maintainers of Tkinter would have documented a guide somewhere. Any thoughts what could be causing this "wtf?" experience?

TAKE NOTE! To support future troubleshooting events, the objective is to understand the root cause so it can reproduced elsewhere, and then apply the fix.

PROBLEM:
The Checkbutton widget does not update, when clicking on the checkbox, on this specific Kubuntu KDE Plasma 5.18 machine configuration.
Tkinter_Checkbox_VisualIssue

INVESTIGATIONS:
This issue did not occur in the following environments:

  1. Windows 8.1,
  2. VirtualBox with LiveCD Kubuntu 20.04 (Plasma 5.18),
  3. VirtualBox with LiveCD Kubuntu 20.10 (Plasma 5.19),
  4. Kubuntu 20.04 (XFCE on original machine).

Tests with other GUI frameworks works correctly.

  1. Kivy
  2. GTK version 3
  3. wxPython

NEXT STEPS:

  1. Search results does not really provide guides or issues related to this specific.
  2. Also ask advice on the python org discuss platform.
  3. Try to create a TCL test version.

SOURCE CODE FOR TEST:

from tkinter import *
class MyGUI:
    def __init__(self, window):
        self.var = IntVar()
        self.c = Checkbutton(window,
                             text="Enable Tab",
                             variable=self.var,
                             command=self.cb)
        self.c.pack()

    def cb(self):
        print("self.var is", self.var.get())

if __name__ == "__main__":
    root = Tk()
    gui = MyGUI(root)
    root.mainloop()

OUTPUT:

>self.var is 1  
>self.var is 0  
>self.var is 1

SYSTEM SPECS:
Operating System: Kubuntu 20.04
KDE Plasma Version: 5.18.5
KDE Frameworks Version: 5.68.0
Qt Version: 5.12.8
Kernel Version: 5.4.0-58-generic
OS Type: 64-bit
Processors: Intel i3 4 Core M350 2.27GHz
Memory: 7,6 GiB of RAM
Python 3.8.5
Tcl/Tk version 8.6

1 Answers

ANSWER, SOLUTION, and CONCLUSION

The root cause is the "Window Text" colour of the "KDE Plasma Color Schemes" that are "Breeze Dark" related result in the Tkinter Checkbutton not being 100% visible due to the text colour being so similar to the checkbox background.

Tkinter_KDEPlasma_BreezeDark_wtxt_Issue

SOLUTION / WORKAROUND
It is recommended to consider styling(themes) when building application GUI's to improve the user's experience by enabling them to change the GUI to some extend. In this case, it would seem Tkinter is using a system setting value intended for an other purpose.

The quickest workaround is to import the tkinter.ttk (Python3) at very least.

    from tkinter import *
    from tkinter.ttk import *

Tkinter_KDEPlasma_BreezeDark_wtxt_Issue_solution

CONCLUSION
This will get updated as more information becomes available I guess. With the issue above, the problem is luckily relatively simple and should be part of a bug confirmation checklist. However, debugging is a lot more complex, vague, or a dark art. Below are some directions to support troubleshooting and investigating Tkinter related issues.

  1. Since Tkinter is a wrapper for the Tcl/tk interpreter, things get tricky. The Tkinter source can be located on GitHub.
  2. Seems like the starting point is to work through the Tcl Developer Xchange. Good references and resources from a rather active community.
Related