PDA

View Full Version : Make True or False a variable



dennisvz
26th April 2019, 18:58
If I have the following snippet of code (from a larger section):


if self.generator.MS == "S":
self.lockSpouseBoxes(True)
else:
self.lockSpouseBoxes(False)

def lockSpouseBoxes(self):

self.ui.lineEdit1.setEnabled(variable for True or False)



How do I modify either/both the top part and the bottom function to carry the True or False from the top part to the function (there will be many line edits to setEnabled true or false). Stated another way, if MS == "S", I want to set a bunch of line edits to "setEnabled(True)" and vice versa. I'm new and not quite sure how to phrase the question.

anda_skoa
26th April 2019, 20:45
Your "lockSpousesBoxes" needs a parameter for the boolean value



def lockSpousesBoxes(self, enable):
self.ui.lineEdit1.setEnabled(enable)


Cheers,
_

dennisvz
26th April 2019, 21:58
Your "lockSpousesBoxes" needs a parameter for the boolean value



def lockSpousesBoxes(self, enable):
self.ui.lineEdit1.setEnabled(enable)


Cheers,
_
'
thanks for your response, but it does not work. I do not understand how the variable 'enable' receives a value of True or False from the code (the "if" statement) above the function? By the way, the code above the function is contained in another function. Sorry, I forgot to mention that.

d_stranz
26th April 2019, 22:56
I do not understand how the variable 'enable' receives a value of True or False from the code

What do you think this line of code does?


self.lockSpouseBoxes(True)

If you don't know, then you really need to learn something about the Python language before you try to write programs using it.

You also need to be very careful about indenting in Python. An indented section in Python is the same as code enclosed in curly braces "{}" in C / C++ - it defines the scope for that section of code. So if your code is really indented the way you pasted it, then I don't have any idea how Python interprets the scope of the lockSpouses function.