'Cannot inherit tkinter classes

Based on an answer from my previous question, I am trying to inherit the tkinter (ttkbootstrap to be precise) classes in this manner:

class _TrWidget:
    def __init__(
        self, type_: Type[ttk.Widget], master: ttk.Widget, text: str, **kwargs
    ):
        type_(master, text=_tr(text), **kwargs)


class _TrButton(_TrWidget, ttk.Button):
    def __init__(self, master: ttk.Widget = None, text: str = "", **kwargs):
        _TrWidget(ttk.Button, master, text, **kwargs)

gives me the error:

AttributeError: '_TrButton' object has no attribute 'tk'

when I do:

button = _TrButton(master, "Button").pack()

Now this might be completely unrelated to tkinter itself, since I haven't used this particular type of inheritance anywhere else.



Solution 1:[1]

class _TrWidget(ttk.Widget):
    def __init__(self, master: ttk.Widget, text: str, **kwargs):
        super().__init__(master, text=_tr(text), **kwargs)


class _TrButton(_TrWidget, ttk.Button):
    def __init__(self, master: ttk.Widget = None, text: str = "", **kwargs):
        super().__init__(master, text, **kwargs)

I don't even know how that worked but it did

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 demberto