how exactly would I get an age validator and a rental cost calculator to work (python tkinter)?
the code I used for the age validator is as follows:
def validate_age():
dob = dob_entry.get()
age = calculate_age(dob)
if age < 24:
tk.Label(text="You must be aged 24 or over to complete this rental form.")
submit_button.config(state="disabled")
else:
tk.Label(text="")
submit_button.config(state="normal")
and the code for the rental cost calculator is as follows:
def calculate_cost():
global rental_cost
# Calculate rental cost based on duration
if rental_label_days >= 1:
rental_cost = 30 * rental_label_days
elif rental_label_weeks >= 1:
rental_cost = 95 * rental_label_weeks
elif rental_label_months >= 1:
rental_cost = 270 * rental_label_months
# Add VAT to rental cost
rental_cost = rental_cost + (rental_cost * 0.2)
# Update the cost label
cost_label.config(text="Total cost: £" + str(round(rental_cost, 2)))
but the error i get when I try to use these are as follows:
age validator:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\corey hopkins\AppData\Local\Programs\Python\Python311\Lib\tkinter\__init__.py", line 1948, in __call__
return self.func(*args)
^^^^^^^^^^^^^^^^
File "C:/Users/corey hopkins/Documents/IT Unit 4/Car Rental Form.py", line 56, in validate_age
submit_button.config(state="disabled")
^^^^^^^^^^^^^
NameError: name 'submit_button' is not defined
rental cost calculator:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\corey hopkins\AppData\Local\Programs\Python\Python311\Lib\tkinter\__init__.py", line 1948, in __call__
return self.func(*args)
^^^^^^^^^^^^^^^^
File "C:/Users/corey hopkins/Documents/IT Unit 4/Car Rental Form.py", line 17, in calculate_cost
if rental_label_days >= 1:
^^^^^^^^^^^^^^^^^^^^^^
TypeError: '>=' not supported between instances of 'Label' and 'int'