dumps41
New Coder
how do i get numberOfItemsHired to accept only 1-500 items, and if not 1-500 display an error message?
This is my code, I've tried
and I've also tried using:
but this does not work as len doesn't work properly with int values. I also tried converting
This is my code, I've tried
Python:
if not int(entry_numberOfItemsHired.get()) >= 1 or int(entry_numberOfItemsHired.get()) <= 500:
Python:
if len(range(int((entry_numberOfItemsHired.get()))) in range (1,500):`
entry_numberOfItemsHired.get()
into int before performing the code but this has not worked either.
Python:
from tkinter import*
import tkinter as tk
def quit():
main_window.destroy()
def print_details():
global counter
counter= 0
Label(main_window, text= "Row").grid(column= 0, row= 7)
Label(main_window, text= "Customer Name").grid(column= 1, row= 7)
Label(main_window, text= "Receipt Number").grid(column= 2, row= 7)
Label(main_window, text= "Item Hired").grid(column= 3, row= 7)
Label(main_window, text= "Number of Item Hired").grid(column= 4, row= 7)
ROWS_ABOVE= 8
while counter < number['total_entries']:
Label(main_window, text= counter).grid(column= 0, row= counter + ROWS_ABOVE)
Label(main_window, text= (hireDetails[counter][0])).grid(column= 1, row= counter + ROWS_ABOVE)
Label(main_window, text= (hireDetails[counter][1])).grid(column= 2, row= counter + ROWS_ABOVE)
Label(main_window, text= (hireDetails[counter][2])).grid(column= 3, row= counter + ROWS_ABOVE)
Label(main_window, text= (hireDetails[counter][3])).grid(column= 4, row= counter + ROWS_ABOVE)
counter += 1
number['counter']= counter
def check_validity():
global items
if (entry_customer_name.get().isalpha()) and (entry_numberOfItemsHired.get().isnumeric())and int(entry_receipt_number.get().isnumeric()) != 0:
if(range(int(entry_receipt_number.get()))) in range (1,99999999):
numberOfItems= int(entry_numberOfItemsHired.get())
minimum_item= 1
maximum_item= 500
if(minimum_item <= (numberOfItems)<= maximum_item) == True:
items= ["Spoons", "Forks" , "Knives" , "Tables" , "Chairs" , "Cater Dishes"]
if (entry_itemHired.get()) in items:
return True
append_details ()
Label(main_window, text= "Customer Name: ").grid(column= 0, row= 1)
Label(main_window, text= "Receipt No.: ").grid(column= 0, row= 2)
Label(main_window, text= "Item Hired: ").grid(column= 0, row= 3)
Label(main_window, text= "No. of Items Hired: ").grid(column= 0, row= 4)
Label(main_window, text= " ").grid(column= 2, row= 1, sticky= "W")
Label(main_window, text= " ").grid(column= 2, row= 2, sticky= "W")
Label(main_window, text= " ").grid(column= 2, row= 3, sticky= "W")
Label(main_window, text= " ").grid(column= 2, row= 4, sticky= "W")
else:
if len(entry_customer_name.get()) == 0:
Label(main_window, text= "Enter Customer Name. No numbers allowed.", bg= 'red').grid(column= 2, row= 1, sticky= "W")
else:
Label(main_window, text= " ").grid(column= 2, row= 1, sticky= "W")
if not(entry_customer_name.get().isalpha()):
Label(main_window, text= "No numbers allowed.", bg= 'red').grid(column= 2, row= 1, sticky= "W")
if len(entry_receipt_number.get()) == 0:
Label(main_window, text= "Receipt Number is invalid.", bg= 'red').grid(column= 2, row= 2, sticky= "W")
else:
Label(main_window, text= " ").grid(column= 2, row= 2, sticky= "W")
if not(entry_receipt_number.get().isnumeric()):
Label(main_window, text= "Receipt Number is invalid. Use digits.", bg= 'red').grid(column= 2, row= 2, sticky= "W")
elif len(range(int(entry_receipt_number.get()))) not in range (1,99999999):
Label(main_window, text= "Receipt Number is invalid. Only 8 digits needed.", bg= 'red').grid(column= 2, row= 2, sticky= "W")
if len(entry_itemHired.get()) == 0:
items= ["Spoons", "Forks" , "Knives" , "Tables" , "Chairs" , "Cater Dishes"]
Label(main_window, text= "Choose Item Hired: Spoons, Forks, Knives, Tables, Chairs, Cater Dishes.", bg= 'red').grid(column= 2, row= 3, sticky= "W")
else:
Label(main_window, text= " ").grid(column= 2, row= 3, sticky= "W")
if (entry_itemHired.get()) not in items:
Label(main_window, text= "Choose Item Hired: Spoons, Forks, Knives, Tables, Chairs, Cater Dishes.", bg= 'red').grid(column= 2, row= 3, sticky= "W")
if len(entry_numberOfItemsHired.get()) == 0:
Label(main_window, text= "Only 1-500 items allowed to be hired.", bg= 'red').grid(column= 2, row= 4, sticky= "W")
return False
if (entry_numberOfItemsHired.get().isalpha()):
Label(main_window, text= "Use Numbers. Only 1-500 items allowed to be hired.", bg= 'red').grid(column= 2, row= 4, sticky= "W")
return False
numberOfItems= int(entry_numberOfItemsHired.get())
minimum_item= 1
maximum_item= 500
if not (minimum_item<= (numberOfItems)<= maximum_item):
Label(main_window, text= "Only 1-500 items allowed to be hired.", bg= 'red').grid(column= 2, row= 4, sticky= "W")
return False
else:
Label(main_window, text= " ").grid(column= 2, row= 4, sticky= "W")
return True
def append_details():
hireDetails.append([entry_customer_name.get(),entry_receipt_number.get(),entry_itemHired.get(),entry_numberOfItemsHired.get()])
entry_customer_name.delete(0,'end')
entry_receipt_number.delete(0,'end')
entry_itemHired.delete(0,'end')
entry_numberOfItemsHired.delete(0,'end')
number ['total_entries'] += 1
def delete_row():
del hireDetails [int(delete_details.get())-0]
counter= number['counter']
number['total_entries']-=1
delete_details.delete(0,'end')
Label(main_window, text= " ").grid(column= 0, row= counter + 7)
Label(main_window, text= " ").grid(column= 1, row= counter + 7)
Label(main_window, text= " ").grid(column= 2, row= counter + 7)
Label(main_window, text= " ").grid(column= 3, row= counter + 7)
Label(main_window, text= " ").grid(column= 4, row= counter + 7)
print_details()
def main():
Button(main_window, text= "Quit", command= quit).grid(column= 4, row= 1)
Button(main_window, text= "Print Details", command= print_details).grid(column= 4, row= 2)
Button(main_window, text= "Append Details", command= check_validity).grid(column= 3, row= 2)
Button(main_window, text= "Delete ", command= delete_row).grid(column= 4, row= 5)
Label(main_window, text= "Customer Name: ").grid(column= 0, row= 1)
Label(main_window, text= "Receipt No.: ").grid(column= 0, row= 2)
Label(main_window, text= "Item Hired: ").grid(column= 0, row= 3)
Label(main_window, text= "No. Of Items Hired: ").grid(column= 0, row= 4)
Label(main_window, text= "Row No. : ").grid(column= 2 , row= 5)
main_window.wm_title("Party Hire Shop - Julies")
main_window.mainloop()
number= {'total_entries':0,'counter':0}
hireDetails= []
main_window= tk.Tk()
entry_customer_name= Entry(main_window)
entry_customer_name.grid(column= 1, row= 1)
entry_receipt_number= Entry(main_window)
entry_receipt_number.grid(column= 1, row= 2)
entry_itemHired= Entry(main_window)
entry_itemHired.grid(column= 1, row= 3)
entry_numberOfItemsHired= Entry(main_window)
entry_numberOfItemsHired.grid(column= 1, row=4)
delete_details= Entry(main_window)
delete_details.grid(column= 3, row= 5)
main()
Last edited by a moderator: