Python Forum
if line edit is empty put in a string
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
if line edit is empty put in a string
#1
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
Reply
#2
Shall we guess on what GUI you use?
Reply
#3
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
Reply
#4
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.
Unless noted otherwise, code in my posts should be understood as "coding suggestions", and its use may require more neurones than the two necessary for Ctrl-C/Ctrl-V.
Your one-stop place for all your GIMP needs: gimp-forum.net
Reply
#5
I would try
if not self.ui.carlabel.text():
   self.ui.carlabel.setText('Other')
Reply
#6
thanks to all of you
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  File "<string>", line 19, in <module> error is related to what? Frankduc 9 12,545 Mar-09-2023, 07:22 AM
Last Post: LocklearSusan
  Writing string to file results in one character per line RB76SFJPsJJDu3bMnwYM 4 1,369 Sep-27-2022, 01:38 PM
Last Post: buran
  -i option changes sys.path (removes leading empty string '') markanth 6 1,976 Aug-26-2022, 09:27 PM
Last Post: markanth
  Inserting line feeds and comments into a beautifulsoup string arbiel 1 1,184 Jul-20-2022, 09:05 AM
Last Post: arbiel
  append a string to a modified line Mr_Blue 10 3,846 Sep-16-2021, 07:24 PM
Last Post: Mr_Blue
  How to capture string from a line to certain line jerald 1 1,899 Jun-30-2021, 05:13 PM
Last Post: Larz60+
  Why is my string empty? karabakh 5 2,391 Jan-30-2021, 04:51 AM
Last Post: karabakh
  How to create new line '/n' at each delimiter in a string? MikeAW2010 3 2,823 Dec-15-2020, 05:21 PM
Last Post: snippsat
  How to print string multiple times on new line ace19887 7 5,730 Sep-30-2020, 02:53 PM
Last Post: buran
  Add new line after finding last string in a region Nigel11 1 1,877 Aug-08-2020, 10:00 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020