Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/322.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在python 3中定义标签时遇到问题_Python - Fatal编程技术网

在python 3中定义标签时遇到问题

在python 3中定义标签时遇到问题,python,Python,我正在编写一个测试程序,它在某种程度上类似于出租商店的库存跟踪器。我正在检查用户输入的数据,但我经常会遇到一个名称错误,其中一个函数没有定义,但我已经定义了它 def check_entries (): #This function checks whether what the user entered is correct for the entry and store global customer_name_error_label global receipt_numb

我正在编写一个测试程序,它在某种程度上类似于出租商店的库存跟踪器。我正在检查用户输入的数据,但我经常会遇到一个名称错误,其中一个函数没有定义,但我已经定义了它

def check_entries (): #This function checks whether what the user entered is correct for the entry and store

    global customer_name_error_label
    global receipt_numb_error_label
    global item_hired_name_error_label
    global numb_items_hired_error_label
    global numb_items_hired_numb_rel_error_label

    if  customer_name_entry.get () .isalpha ()  and   receipt_number_entry.get().isdigit() and  item_hired_entry.get () .isalpha ():
        if number_of_items_hired_entry.get () .isdigit () and int (number_of_items_hired_entry.get () ) >0 and int (number_of_items_hired_entry.get () )  <500:

            customer_name_error_label.grid_forget ()
            receipt_numb_error_label.grid_forget ()
            item_hired_name_error_label.grid_forget ()
            numb_items_hired_error_label.grid_forget ()
            numb_items_hired_numb_rel_error_label.grid_forget ()
            append_lists ()

   
    else: 

           if customer_name_entry.get () .isalpha () ==False:
            customer_name_error_label=Label (main_frame,text="Please enter a name that only has letters,no numbers ,and there must be a name entered ",bg='red')
            customer_name_error_label.grid (row=0,column=3)
     
            if receipt_number_entry.get () .isdigit() ==False:
                receipt_numb_error_label=Label (main_frame,text="Please enter a receipt number that is only a number and doesn't have any letters or symbols.",bg='red')
                receipt_numb_error_label.grid(row=1,column=3)

            if item_hired_entry.get () .isalpha ()== False:
                item_hired_name_error_label=Label (main_frame,text="Please enter a item name that only has letters,numbers and symbols aren't accepted.",bg='red')
                item_hired_name_error_label.grid (row=2,column=3)
           
           if number_of_items_hired_entry.get ().isdigit ()== False:
               numb_items_hired_error_label=Label (main_frame,text="The number of items hired can only be a number,symbols,and letters aren't accepted.",bg='red')
               numb_items_hired_error_label.grid (row=4,column=3)

           if int (number_of_items_hired_entry.get () ) <0 and int (number_of_items_hired_entry.get () ) >500:
               numb_items_hired_numb_rel_error_label=Label (main_frame,text="The number of items hired can only be more then 0 and less then 500",bg='red')
               numb_items_hired_numb_rel_error_label.grid (row=5,column=2)

你为什么不相信这个错误消息?它表示您从未定义过
客户\名称\错误\标签
global
不是一个变量声明语句。显然,试图访问
customer\u name\u error\u label
的代码在分配给
customer\u name\u error\u label
的代码之前被命中。大概第19行是在定义它之前执行的。我需要在声明之前使用它,因为这是我知道的唯一方法,在用户输入正确的名称和数字以及if语句之后,在遇到else之前删除错误标签,并且错误警告消失。