Python Forum
Issue in Tkinter with winfo_class() and LabelFrame - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: GUI (https://python-forum.io/forum-10.html)
+--- Thread: Issue in Tkinter with winfo_class() and LabelFrame (/thread-30096.html)



Issue in Tkinter with winfo_class() and LabelFrame - ReDefendeur - Oct-04-2020

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


RE: Issue in Tkinter with winfo_class() and LabelFrame - Jeff900 - Oct-05-2020

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