python - set the text of an entry using a button tkinter -
i trying set text of entry using button in gui using tkinter. gui me classify thousands of words. 5 categories, each of categories has button. hoping using button speed me , want double check words every time otherwise use button , have gui process current word , bring next word. command buttons reason not behaving want them to. example
def cwin(): win = tk() v=stringvar() def settext(word): v.set(word) = button(win, text="plant", command=settext("plant") a.pack() b = button(win, text="animal",command=settext("animal")) b.pack() c = entry(win, textvariable=v) c.pack() win.mainloop()
so far when able compile click nothing.
you might want use insert
method.
this script inserts text entry
. inserted text can changed in command
parameter of button.
from tkinter import * def set_text(text): e.delete(0,end) e.insert(0,text) return win = tk() e = entry(win,width=10) e.pack() b1 = button(win,text="animal",command=lambda:set_text("animal")) b1.pack() b2 = button(win,text="plant",command=lambda:set_text("plant")) b2.pack() win.mainloop()
Comments
Post a Comment