Tkinter module test: widget class not inserted in application frame

MRAB python at mrabarnett.plus.com
Fri Jun 17 14:28:12 EDT 2022


On 2022-06-17 18:06, Rich Shepard wrote:
> On Fri, 17 Jun 2022, MRAB wrote:
> 
>> You haven't shown the code for common_classes.LabelInput, but I'm guessing 
>> that the first argument should be the parent.
> 
[snip]
>> You're passing in the _class_ ConactNameInput, but I'm guessing that it 
>> should be an _instance_ of that class, in this case, 'self'.
> 
> Haven't I done this in the application class?
> class NameApplication(tk.Tk):
>       def __init__(self, *args, **kwargs):
>           super().__init__(*args, **kwargs)
>           self.title("Contact Name")
>           self.geometry("800x600")
>           self.resizable(width = False, height = False)
>           ContactNameInput(self).grid(row = 0, column = 0, sticky=('EWNS'))
>           self.columnconfigure(0, weight=1)
> 
> If not, where do I specify the instance of the ContactNameInput class?
> 
This:

          self.inputs['Last name'] = cc.LabelInput(
              ContactNameInput, 'lname',
              input_class = ttk.Entry,
              input_var = tk.StringVar()
              )

should be this:

          self.inputs['Last name'] = cc.LabelInput(
              self, 'lname',
              input_class = ttk.Entry,
              input_var = tk.StringVar()
              )

Also, this:

          self.inputs['First name'] = cc.LabelInput(
              ContactNameInput, 'fname',
              input_class = ttk.Entry,
              input_var = tk.StringVar()
              )

should be this:

          self.inputs['First name'] = cc.LabelInput(
              self, 'fname',
              input_class = ttk.Entry,
              input_var = tk.StringVar()
              )


More information about the Python-list mailing list