Python Forum
Cancel update of text of QPlainTextEdit if terms not satisfied
Thread Rating:
  • 2 Vote(s) - 1.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Cancel update of text of QPlainTextEdit if terms not satisfied
#1
I have a QPlainTextEdit 's textChanged event connected to _criterion_txt_textChanged function.
I want the user not to able to enter a value grater than 2 and smaller than 1.
It can be int or decimal (float).
When terms are not satisfied, I want to set it's text to '1'.
(or maybe cancel update if possible)

This is what I've done, but not working.


def _criterion_txt_textChanged(self):
        if not re.match("\d*\.?\d*", criterion_txt.toPlainText()):
            msg =  "Only integers and decimals allowed, from 1 up to 2"
            print(msg)
            criterion_txt.setPlainText("1")
        try:
            text = float(criterion_txt.toPlainText())
        except:
            criterion_txt.setPlainText("1")
            msg = "Only integers and decimals allowed, from 1 up to 2"
            print(msg)
            
How can I achieve this?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] Make my button text update? Skata100 1 2,012 Aug-07-2021, 05:37 AM
Last Post: deanhystad
  update text variable on label with keypress knoxvilles_joker 3 4,841 Apr-17-2021, 11:21 PM
Last Post: knoxvilles_joker
  [Tkinter] how to update label text from list Roshan 8 5,371 Apr-25-2020, 08:04 AM
Last Post: Roshan
  Update a label text from subprocess jim53 3 4,288 Aug-19-2019, 08:21 PM
Last Post: Denni
  Unable to update or refresh label text in tkinter jenkins43 3 6,508 Jul-24-2019, 02:09 PM
Last Post: Friend
  Update value selected in option menu when select an item from text box klllmmm 2 4,953 Jun-06-2019, 04:51 AM
Last Post: klllmmm
  Display and update the label text which display the serial value jenkins43 5 8,990 Feb-04-2019, 04:36 AM
Last Post: Larz60+
  [Tkinter] update the content of Text widget atlass218 10 16,082 Dec-15-2018, 11:51 AM
Last Post: atlass218

Forum Jump:

User Panel Messages

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