code: def do_rstrip(self, event=None):
      text = self.editwin.text
      undo = self.editwin.undo
      undo.undo_block_start()
  
      end_line = int(float(text.index("end")))
      for cur in range(1, end_line):
          txt = text.get("%i.0" % cur, "%i.end" % cur)
          raw = len(txt)
          cut = len(txt.rstrip())
          # Since text.delete() marks file as changed, even if not,
          # only call it when needed to actually delete something.
          if cut < raw:
              text.delete("%i.%i" % (cur, cut), "%i.end" % cur)
  
      if text.get(
          "end-2c"
      ) == "\n" and not hasattr(  # File ends with at least 1 newline;
          self.editwin, "interp"
      ):  # & is not Shell.
          # Delete extra user endlines.
          while (
              text.index("end-1c") > "1.0"  # Stop if file empty.
              and text.get("end-3c") == "\n"
          ):
              text.delete("end-3c")
          # Because tk indexes are slice indexes and never raise,
          # a file with only newlines will be emptied.
          # patchcheck.py does the same.
  
      undo.undo_block_stop()
  
imports: import re
  from tkinter.messagebox import askyesno
  from tkinter.simpledialog import askinteger
  from idlelib.config import idleConf
label_desc: Use image node_id 2 for calling the Rstrip obj's underlying member method code with example usage: obj.do_rstrip(event) without return types