Python Tkinter Text Area set cursor to end - python

I have a Tkinter Text() object and I append lines to it using .insert(END, string). When the text fills the available area, I'd expect it to scroll down to show the bottom line of text in the view, but it doesn't scroll (meaning the user has to scroll themselves to see the latest text). I've had a look at the mark_set() method but I can't seem to figure out how to get the cursor to the index of the last item of text.
Any help would be appreciated :)

As usual with Tkinter, there are a number of ways to do this, but one is the easiest: Text.see:
text.insert(END, "spam\n")
text.see(END)
If you want to make sure the start of the new text is visible, not the end of it, or if you only want to do this if the end was already visible beforehand or if the text is active, etc., you may need to look at the other options: scan_mark/scan_dragto, or yview and friends.

Related

How to access the start and end index of a selected text from kivy textinput

That's my doubt. How to access the first and last index of the selected text in kivy-TextInput. And also if possible can u tell me how to get the selected text.... I tried TextInput.selection_text but it just gives ''. Nothing else.. Hope that no code or example is needed

Python Tkinter cant unbind Triple Click

So I have some tags (strings the user made), they are on display in a text widget at all times. Basically if there are tags to display, you need to be able to triple click on them and it will lead to a editing menu. But if there aren't any tags to display, I don't want people to be able to triple click on it.
So my thought was bind triple click to the appropriate function if there are tags to display, and unbind it if there aren't any tags to display.
for tag in sorted(tags_pre_listed):#This loop will just check the tags and OK them for use.
if tag[0:4]=='TAG-' and tag not in used_tags: # Just avoids duplicates.
tags_display_box.insert(Tk.END, '#'+tag[4:]+' ') #inserts the tag to the display.
used_tags.append(tag)
if len(used_tags)>0: #If any tags were used to display, it will bind Triple click.
tags_display_box.bind("<Triple-1>", delete_tag)
else: #This is where it tries to unbind if there are no tags, but fails.
tags_display_box.unbind('<Button-1>',"<Triple-1>")
The issue I get is
TclError: can't delete Tcl command
Sorry It may be a rookie answer for all I know but I have done my research and can't find a way around it at all T-T
Thanks so much for reading and for any advice!
The line:
tags_display_box.unbind('<Button 1>',"<Triple-1>")
should read:
tags_display_box.unbind('<Triple-1>')
As it is you're trying to unbind something that's not bound from a command that does not exist.

Add New line in pygtk Treeview

I'm using gtk treeview in one of my applications.
Application works as follows:
I extract some data from logfile and add the important data to my splite database and then, I show the data in treeview by fetching the rows from the database.
Now my question is how can I add newline character, so that I can add multi-lines in the treeview cellrenderer.
I tried this by setting the cellrenderer "markup" property and then tried adding "\n" and then with the tag. In case of "\n" it prints the "\n" as it is in the treeview cell. And gives following error if I try to add tag.
GtkWarning: Failed to set text from markup due to error parsing markup: Unknown tag 'br' on line 1 char 18
gtk.main()
So how can I add multilines to a gtk treeview cell?
Thanks in advance
With regards to automatically flowing text, CellRendererText should just do the right thing if you set wrap-width property to a value that isn't -1.
If automatic wrapping is not enough and you really need separate paragraphs, I think you may need to implement your own CellRenderer (which is not trivial) or use another container like a ListBox (where custom widgets are easy, but which will mean throwing away your treeview code...).

PyQt:How do I get the current tablewidget in a tabs widget?

I have a tab widget with tablewidgets in each one, containing cells with links.I know how to get the current text from a tablewidget and open it in a browser,which is what i want to do.
selection=str(self.tableWidget_1.currentItem().text()).encode('utf8')
webbrowser.open(selection,new=2)
My problem is that I don't know how to get the current tablewidget instead of predetermined like above.Any ideas?Thanks.
See QTabWidget.currentWidget.

Text in Text Widget as a variable

so I've got this little Text widget with a scroll bar and I've got a question. How do I make text in this Text widget a variable ? If I made this text a variable I would be able to open a text file and edit it's text or save the text I've written, etc or maybe it's a wrong way that I'm approaching this, is there a better way to do this ?
There is no option to associate a variable with a text widget. You can achieve the same thing by using variable traces and widget bindings but it's rarely worth the effort.
The typical way to interact with the text widget is to read a file into a variable then use the insert method of the widget to put the text into the widget. Then, to save you just do the reverse -- get the text from the widget with the get method, and write the data to a file.
One tip: when you do a get, don't get the text from 1.0 to "end", use "end-1c" instead. If you specify "end" as the last character you'll get the implicit newline that tk always adds, meaning your text file will grow by one character each time you do a load/save cycle.

Categories