# Subclass Tkinter Widgets to save typing

I am doing a small GUI program for a practice exercise and in order to save myself some typing I took it upon myself to subclass some Tkinter widgets so I can pass the grid placement in the instantiation. One of my subclasses looks like this:

import tkinter as tk
class EntryBox(tk.Entry):
super().__init__(master=master, width=width, relief=relief, **kwargs)


And one of my instances of this widget looks like this:

window = tk.Tk()

title_entry = EntryBox(window, 10, 'sunken', 0, 1)

window.mainloop()


My initial thinking for the subclass is that if I am creating these entry widgets, they will clearly be visible on the screen (similar for some Labels, text areas, buttons, etc...). So this would save many lines of code and typing.

Is it appropriate to subclass these widgets to save typing, or does this typically cause more confusion when another programmer reads it? Also, will this be considered more error-prone? (Perhaps it would still be best to pass named parameter in my instantiation?)

I'd like to get some comments on when it's good practice / appropriate to subclass and when it causes more confusion.

I wanted to add that I decided to pass default values in the init subclass method so that if someone wanted to call the grid methods in the traditional way they still could in the code.

However, as Tkinter does not have a EntryBox() class, it would be better to rename this, in order not to confuse the reader of your code, to rename it to something like: CustomEntry() or, why not, CustomEntryWidget().
• Thanks for the feedback, I appreciate it. I'm curious if you could expand on why it might not be wise to call the grid method at instantiation? For example, my thinking was that the widgets I subclassed would all be displayed on the screen, so my thought was that I could save myself lines of code by passing arguments to the instance. I also considered a parameter in init grid=False like this: def __init__(self, master=None, grid=False), then using something like if grid=True: self.grid(args here). – Hanzy Oct 19 '17 at 17:42