Python Forum

Full Version: Issue in Tkinter with winfo_class() and LabelFrame
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,
I'm ReDefendeur and I would like to tell you about a potential bug that I found in Tkinter.

When we do widget.winfo_class()
this returns the class of the widget so I use it with a getattr(object, name[, default]) however for the class
LabelFrame, it returns Labelframe (no Shift to "F") which creates an error

import tkinter as tk

root = tk.Tk()
widget = tk.LabelFrame(root)

widget_class = widget.winfo_class()

# with bad class
print(widget_class)
try:
    getattr(tk, widget_class)(root)
    print("OK")
except AttributeError:
    print("ERROR")

# corrected
if widget_class == "Labelframe":
    widget_class = "LabelFrame"
try:
    getattr(tk, widget_class)(root)
    print("OK")
except AttributeError:
    print("ERROR")
Output:
Labelframe ERROR OK
Thank you for your answers
Hi ReDefendeur, I'm not really familiar with tkinter. So I can't tell if this is really a bug. Anyway, this forum is not really the place for reporting potential bugs. Probably this is the right place for you to look: https://docs.python.org/3/bugs.html