I have software that handles dates, written as follows:
def EscolheDataInicio():
controle1 = None
controle2 = None
if controle1 == None:
teste = easygui.ccbox(msg="Escolher data início?", title="Escolher data de início", choices=('[O]k', '[C]ancel'))
if teste == False:
controle1 = 1
else:
while controle1 == None:
controle1 = easygui.enterbox(msg="Insira data início", title="Definir data início")
ValidaDataInicio() #Testa se a entrada corresponde a uma data em formato válido...
EscolheDataFim() #Chama função correlata para inserção de data final do intervalo.
The idea is to set a date range ( controle1
and controle2
) OU to set a default reference date determined by the system (if you cancel CCBOX, the program will assume that it do not want to insert a date range, and will set controle1
to 1
, exiting the loop.
The question is: how do I keep this 1
, so that the program DOES NOT ENTER the function again, since I declare controle1
as None
as LOCAL variable every call? I've already tried to declare controle1
as None
OUTSIDE the function, and insert a global controle1
into the function, but then it returns the error "NameError: name 'controle1' is not defined"
.
I want it to ask this interval once .
In vdd the whole code is much more extensive, but basically this is:
controle1 = None
controle2 = None
def EscolheDataInicio():
global controle1
global controle2
if controle1 == None:
teste = easygui.ccbox(msg="Escolher data início?", title="Escolher data de início", choices=('[O]k', '[C]ancel'))
if teste == False:
controle1 = 1
else:
while controle1 == None:
controle1 = easygui.enterbox(msg="Insira data início", title="Definir data início")
ValidaDataInicio()
EscolheDataFim()