Entry field values are not getting printed - Python

38 views Asked by At

When I enter the values for all entry fields in the "Rating data labels", all values getting printed except input line voltage and output line voltage. Also, I get the error message that "All rating data input fields must be filled" as the code does not capture the values in input line voltage and output line voltage. can somebody explain why? Thanks

    # Rating Data Labels
    labels = ["KVA Rating:", "IT Type:", "Input line voltage:", "Output line voltage:",
              "Frequency:", "Connection type:", "Current Density:", "Flux Density:",
              "Conductor material:"]
    for i, label_text in enumerate(labels):
        tk.Label(self.input_frame, text=label_text).grid(row=i + 3, column=0, sticky="w")

    
    # Entry fields
    self.entries = {}
    # Rating data entry
    entry_values = ["KVA Rating", "IT Type", "Input line voltage", "Output line voltage", "Frequency",
                    "Connection type",
                    "Current Density", "Flux Density", "Conductor material"]
    for i, value in enumerate(entry_values):
        entry = ttk.Entry(self.input_frame)
        entry.grid(row=i + 3, column=1, padx=1, pady=1)
        self.entries["entry_" + str(i)] = entry  # Use unique keys

def calculate(self):
    try:
        # Get values from entry fields
        values = [entry.get() for entry in self.entries.values()]
        print("Values:", values)

        # Perform calculations
        # Check for empty fields in Rating data
        if any(value == '' for value in values[:9]):
            raise ValueError("All Rating data input fields must be filled.")

        # Rating data
        kva_rating = float(values[0])
        isolation_transformer_type = str(values[1])
        input_line_voltage = float(values[2])
        output_line_voltage = float(values[3])
        frequency = float(values[4])
        connection_type = str(values[5])
        current_density = float(values[6])
        flux_density = float(values[7])
        conductor_material = str(values[8])

        

I tried to print the values to check whether all the fields are capturing the entry field values and found that two fields are empty even though I enter values there.

0

There are 0 answers