This is very normal for subclassing a widget to create a custom one. However, if this custom widget consists of more than one widget, you will usually be a subclass of Frame . For example, to create a widget that is a text widget with a scroll bar, I would do something like this:
import Tkinter as tk class ScrolledText(tk.Frame): def __init__(self, parent, *args, **kwargs): tk.Frame.__init__(self, parent) self.text = tk.Text(self, *args, **kwargs) self.vsb = tk.Scrollbar(self, orient="vertical", command=self.text.yview) self.text.configure(yscrollcommand=self.vsb.set) self.vsb.pack(side="right", fill="y") self.text.pack(side="left", fill="both", expand=True) class Example(tk.Frame): def __init__(self, parent): tk.Frame.__init__(self, parent) self.scrolled_text = ScrolledText(self) self.scrolled_text.pack(side="top", fill="both", expand=True) with open(__file__, "r") as f: self.scrolled_text.text.insert("1.0", f.read()) root = tk.Tk() Example(root).pack(side="top", fill="both", expand=True) root.mainloop()
With this approach, pay attention to how you need to reference the internal text widget when inserting text. If you want this widget to look more like a real text widget, you can create a mapping to some or all of the functions of the text widget. For instance:
import Tkinter as tk class ScrolledText(tk.Frame): def __init__(self, parent, *args, **kwargs): tk.Frame.__init__(self, parent) self.text = tk.Text(self, *args, **kwargs) self.vsb = tk.Scrollbar(self, orient="vertical", command=self.text.yview) self.text.configure(yscrollcommand=self.vsb.set) self.vsb.pack(side="right", fill="y") self.text.pack(side="left", fill="both", expand=True) # expose some text methods as methods on this object self.insert = self.text.insert self.delete = self.text.delete self.mark_set = self.text.mark_set self.get = self.text.get self.index = self.text.index self.search = self.text.search class Example(tk.Frame): def __init__(self, parent): tk.Frame.__init__(self, parent) self.scrolled_text = ScrolledText(self) self.scrolled_text.pack(side="top", fill="both", expand=True) with open(__file__, "r") as f: self.scrolled_text.insert("1.0", f.read()) root = tk.Tk() Example(root).pack(side="top", fill="both", expand=True) root.mainloop()