textbox - Python 3.4 Tkinter - How can I just delete a string anywhere in a text widget? -


If you need more details, I am happy to provide it, but rather provide me the scenario.

I did this to insert the HTML line breaks in my text:

  count = int (text_entry.index ('end-1c'). Split (' . ') [0]) in (calculation): if i! = 0.0: text_entry.insert ('% d.end'% i, '
')

Just keep it, after I execute my remaining function this lesson I want to return, I want to return the text to its original state. I tried to use text.delete () and text.replace () , but let me Do not think just remove the inserted string without changing the rest of the text. I'm new to the tanker, so I'm sure I do not understand the index or some basic usage.

I appreciate your time and attention.

There is a method in the text widget that you want to remove the text of any category . It does exactly what she should do - give it two letters and it will remove the text between them.

For example, you can remove the entire second line of text:

  text_entry.delete ("2.0", "3.0")   

If you are trying to remember the categories of text so that you can delete them later, make sure that you have the top down. If you delete from the top down, all saved indexes will be inaccurate due to the first deletion. If you want to remove line 2 and 4, when you delete line 2, line 4 becomes line 3, etc. If you delete the first row, the line number of all the previous rows is unaffected.

If you only want to undo a series of actions, you can call the program methodically. Since the Undo mechanism is a little less-documentary for the connector I will include an example. The main points are:

  1. Set undo = true in the text widget
  2. Call edit_undo () before calling edit_separator () before adding , which will undo everything in the moment of the last separator

    This last point is important - - If you allow the user to enter other data, the separators are automatically added. This trick works best when there is no contact between the time of inserting a group of your data and then undo those inserts

    Here is a work example: < Ex: Import the tinker as an example of the vaccine class (tk.Frame): def __init __ (self, guardian): tk.frame .__ init __ (self, parent) self Tollbar = tt.fr (auto) itself (scroller = "top", fill = "x") do_button = tk.button (auto.Tolbar, text = "do it", command = self.do_it) undo_button = Tk.Button (self.toolbar, text = "undo it", command = self.undo_it) do_button.pack (side = "left") undo_button.pack (side = "left") self.text = tk.Text ( Self, "wrap" = "word", undo = true) as self.text.pack (fill = "both", expansion = true) open (__file__, "r") f: self.text.insert ("1.0 ", f.read (): def do_it (self): self.text.edit_separator () count = int (self.text.index ('end-1c'). partition ('.') [0]) In category (1, count): self.text.insert ('% d.end'% i, '
    ') text = self.text .get ("1.0", "end-1c") def undo_it (self): self.text.edit_undo () if __name__ == "__main__": root = tk.Tk () example (root) .pack (fill = "Both", extension = true) root.mainloop ()

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -