Creating a Tkinter Button to 'clear' Output -
i have basic program spits out string of values, not quite sure how clear these values. @ moment have set exit window , start new 1 i'm not rewriting on new values time. there simple way add button says 'clear' , that? code below:
def create_widgets(self): self.entrylabel = label(self, text="please enter list of numbers:") self.entrylabel.grid(row=0, column=0, columnspan=2) self.listentry = entry(self) self.listentry.grid(row=0, column=2, sticky=e) self.entrylabel = label(self, text="please enter index value:") self.entrylabel.grid(row=1, column=0, columnspan=2, sticky=e) self.indexentry = entry(self) self.indexentry.grid(row=1, column=2) self.runbttn = button(self, text="run function", command=self.psifunction) self.runbttn.grid(row=2, column=0, sticky=w) self.answerlabel = label(self, text="output list:") self.answerlabel.grid(row=2, column=1, sticky=w) self.clearbttn = button(self, text="clear output", command=) self.clearbttn.grid(row=3, column=0, sticky=w) def clear(): config.self.entrylabel(text="") tk.button(text="write", command=write).grid() tk.button(text="clear", command=clear).grid() self.clearbttn = button(self, text="clear output", command=clear) self.clearbttn.grid(row=3, column=0, sticky=w)
you kinda asked 2 different questions here. i'll address first, since came in with. change label, update text using config
method:
import tkinter tk root = tk.tk() label = tk.label() label.grid() def write(): label.config(text="blah"*6) def clear(): label.config(text="") tk.button(text="write", command=write).grid() tk.button(text="clear", command=clear).grid() root.mainloop()
Comments
Post a Comment