user interface - python GUI button manipulates label text -
hej,
i want program gui in python compares prompted word (from list) entry. shall possible several times, want make button erases both entry , label , prompts next word list. thus, clicking button shall manipulate text displayed on label. bus how do this?
my code excerpt is:
from tkinter import * = 0 vocablist = ['one', 'two', 'three'] np.random.shuffle(vocablist) vocab = vocablist[i] (...) class simpleapp_tk(tkinter.tk): def __init__(self,parent): tkinter.tk.__init__(self,parent) self.parent = parent self.initialize() (...) self.label = tkinter.label(self, text=vocab,anchor="w") self.label.grid(column=1,row=0) def clear_text(): global self.entry.delete(0, 'end') += 1 # don't know if works! self.label.insert(0, vocab) # not work! button_next = tkinter.button(self,text=u"next", command=clear_text) button_next.grid(column=1,row=1) if __name__ == "__main__": app = simpleapp_tk(none) app.title('rehearse vocabulary: translate!') app.mainloop()
i tried
self.label.config(text=vocab)
instead of .insert-function.
i wondering if problem command or if not work update counter , automatically update variable "vocab" next element list?
thanks help!
try using widget['attribute'] = 'value'
. following:
def action(event=none): # event in case bind keypress entry.delete('0', end) # clear entry label['text'] = "" # set label's widget text "" next_word()
where entry
entry widget, label
label , next_word()
prompts next word.
Comments
Post a Comment