Reference a Label in a Component Form to fill it

I’ve just started moving parts of my form into components and one of these is a section that prints the prices of a quote calculation

All of the calculations are coded into the parent form.

      self.label_subtotal.text = "£ {:.2f}".format(self.subtotal)
      self.label_totalipt.text = "£ {:.2f}".format(self.totalipt)
      self.label_totalpremium.text = "£ {:.2f}".format(self.totalpremium)

I get this error
AttributeError: 'Quotation' object has no attribute 'label_subtotal'

I’ve referenced the component form at the top of the page


from .QuotationPrice import QuotationPrice

Here is the component class at the top of the child page

class QuotationPrice(QuotationPriceTemplate):
  def __init__(self, **properties):
    # Set Form properties and Data Bindings.
    self.init_components(**properties)

What am I missing when referencing the label?

In your parent form, when you use self. you are referencing properties of the parent form. Your label_subtotal is not a property of the parent form, but of your QuotationPrice form.

Somewhere you should have a reference to the instance of QuotationPrice that you inserted into the parent form. You need to use that reference instead of self.

1 Like

Ahh I did try to add that and tried a few combinations, but didn’t remove self.

I’m still getting that error, this is what I have now:

    QuotationPrice.label_subtotal.text = "£ {:.2f}".format(self.subtotal)
      QuotationPrice.label_totalipt.text = "£ {:.2f}".format(self.totalipt)
      QuotationPrice.label_totalpremium.text = "£ {:.2f}".format(self.totalpremium)

AttributeError: type object 'QuotationPrice' has no attribute 'label_subtotal'

Where are you creating the instance of QuotationPrice? That’s the reference you want to use.

so that is called on the main Quotation page. I also changed the label name, as I copied and pasted the label, just in case there was an issue there, but no.

Originally, the price section was in the main page, but they I created a sub form, named it as a custom component and then added that component back into the main Quotation page

I’m not seeing an actual reference to a QuotationPrice instance. How are you creating the instance of QuotationPrice? Did you drag and drop QuotationPrice onto the Quotation form? Did you dynamically create an instance in code?

You’re using a class name to try to access instance variables. That isn’t going to work. You need a reference to an instance of the class.

If, for example, you dragged and dropped QuotationPrice onto your Quotation form, then that component has a name on Quotation. Maybe something like self.custom_1? Find that name and use that as your reference, e.g. self.custom_1.subtotal.text

If you created the instance dynamically through code, then you have a reference somewhere to that QuotationPrice instance. Use that reference instead.

1 Like

got you!

it was self.quotation_price.subtotal.text.

Thank you for that.

1 Like