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.
Related
eleUserMessage = driver.find_element_by_id("xxxxxxx")
eleUserMessage.send_keys(email)
Im trying to use selenium with python to auto fill out a form and fill in my details. So far I have read in my info from a .txt file and stored them in variables for easy reference. When I Find the element and try to fill it out with send_keys, after each send_keys line, the form highlights the other fields that aren't filled in and says I need to fill them in before I submit. My code to submit the info is way after this code segment.
Why does send_keys try to submit the form or even send the enter key when I didn't tell it to? and how do I stop this from happening?
The main issue that this is causing is that the element ids change when they are highlighted in red since they are required fields. I need to get around that somehow. Please let me know what I can do.
Because you are storing your details in a text file, it is likely that when you create the email variable there is a newline at the end of the string as this is how text files work. This would explain why the form gets submitted because it is the equivalent of typing the email followed by the enter key. You can try to fix this by using
eleUserMessage.send_keys(email.rstrip())
rstrip() is a builtin function and it by default, with no parameters, strips the whitespace and newlines from the right side.
if you just want to fill out a form ,then submit the finished form.
you can try :
eleUserMessage = driver.find_element_by_xpath("//select[#name='name']")
all_options = eleUserMessage.find_elements_by_tag_name("option")
for option in all_options:
print("Value is: %s" % option.get_attribute("value"))
option.click()
eleUserMessage.send_keys(email)
i am trying to program text editor by using tkinter.
this is the mark function:
self.text.tag_add("Mark",tk.SEL_FIRST,tk.SEL_LAST)
self.text.tag_config("Mark",background="yellow",foreground="black")
and this is the unmark function
self.text.tag_add("UnMark",tk.SEL_FIRST,tk.SEL_LAST)
self.text.tag_config("UnMark",background="white",foreground = "black")
but the problem is when i mark the text and then unmark it, i cant mark it again.
the mark function dont work when i try to mark the text again that i unmarked it.
The reason is because the "UnMark" tag has a higher priority than the "Mark" tag. You can add the "Mark" tag, but the configuration of "UnMark" takes precedence.
I recommend instead of an "UnMark" tag, you simply remove the "Mark" tag when you don't want something to be marked.
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...).
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.
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.