if line edit is empty put in a string - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: if line edit is empty put in a string (/thread-2426.html) |
if line edit is empty put in a string - birdieman - Mar-15-2017 I am trying to see if a line edit is empty, and if so, put the word Other in it. What I have so far crashes if len(self.ui.carlabel) == 0: self.ui.carlabel.setText(str('Other'))by the way, "carlabel" is a line edit, not a label thanks RE: if line edit is empty put in a string - snippsat - Mar-15-2017 Shall we guess on what GUI you use? RE: if line edit is empty put in a string - birdieman - Mar-15-2017 sorry, I am using PyQt5 -- but I think I just need to know if (1) is the IF statement the correct way to see if a line edit is empty? and (2) the syntax of putting the word Other into a line edit. For now, assume the self.ui part is correct. thanks for responding RE: if line edit is empty put in a string - Ofnuts - Mar-16-2017 Statement likely incorrect. You are taking the length of the widget, not of the text inside it. Try if len(self.ui.carlabel.text()) == 0: if len(self.ui.carlabel.getText()) == 0:or whatever method gets you the text of the widget. RE: if line edit is empty put in a string - buran - Mar-16-2017 I would try if not self.ui.carlabel.text(): self.ui.carlabel.setText('Other') RE: if line edit is empty put in a string - birdieman - Mar-16-2017 thanks to all of you |