Nov-09-2023, 01:56 PM
if, if and should. I can't imagine why that might not return something.
That is some ugly code. A lot of the ugly is from using Entry. Entry is a terrible choice for entering information. For entering an integer I would think about using a spinbox. For entering departure or destination I would look at using a checkbox or option menu
If you want to use Entry I suggest subclassing Entry to make an IntEntry and an ListEntry that force users to enter valid information. These would have validation built into the control, so you don't have to write extra code to validate each entry object's value. The beauty of writing an Entry sublcass that does the validation is you only feel the pain once, when you write the sublcass. Currently you are feeling the pain each time you use an Entry widget to enter a number.
After you get the entry part fixed, you should change how your code uses the information. Your code should not allow the user to check a flight if there are errors in any of the entries. If your form has a submit button, I would disable the button if the form is not valid. Another choice is the submit button first checks the form, and only executes the submit callback if all the entries are valid. The more you can separate the data entry part of the program from the doing work part of the program, the cleaner and more robust your code will be.
That is some ugly code. A lot of the ugly is from using Entry. Entry is a terrible choice for entering information. For entering an integer I would think about using a spinbox. For entering departure or destination I would look at using a checkbox or option menu
If you want to use Entry I suggest subclassing Entry to make an IntEntry and an ListEntry that force users to enter valid information. These would have validation built into the control, so you don't have to write extra code to validate each entry object's value. The beauty of writing an Entry sublcass that does the validation is you only feel the pain once, when you write the sublcass. Currently you are feeling the pain each time you use an Entry widget to enter a number.
After you get the entry part fixed, you should change how your code uses the information. Your code should not allow the user to check a flight if there are errors in any of the entries. If your form has a submit button, I would disable the button if the form is not valid. Another choice is the submit button first checks the form, and only executes the submit callback if all the entries are valid. The more you can separate the data entry part of the program from the doing work part of the program, the cleaner and more robust your code will be.