python - Obtaining widget values in tkinter -


how refer widget values in following code.here have added widgets calling methods in app class different frames.next,i want access values in widgets(which user enters) of frames @ same time.but not able figure out how should refer them , access values!

class myapp():     def __init__(self,parent):         self.parent=parent         self.container=frame(self.parent)         self.container.pack()          self.tab1=button(self.container,text='tab1',command=self.tab1click)         self.tab2=button(self.container,text='tab*emphasized text*2',command=self.tab2click)         self.tab1.pack()         self.tab2.pack()     def tab1click(self):         top=toplevel()         self.container1=frame(top)          self.add_widget1(self.container1)#self.add_widgeti(parent) method in myapp() class add widget frame         self.add_widget2(self.container1)         self.add_widget3(self.container1)          self.container1.pack()      def tab2click(self):         top=toplevel()         self.container2=frame(top)          self.add_widget2(self.container2)         self.add_widget4(self.container2)         self.add_widget5(self.container2)          self.container2.pack()      def write(self):         #here want write values contained in widgets in both frames in file,but not able figure out how refer them , access values. 

any highly appreciated.thanks in advance.

the widgets in user can write have get method returns content. in order this, need store widget in class variable example.

edit: had misunderstood problem , hadn't realized add_widget function called different containers same instance. 1 way keep track of created widgets create widget list:

  • add self.widgets = [] in __init__

  • define theadd_widget method that:

def add_widget(self, container):         self.widgets.append(entry(container, text="enter text here"))         self.widgets[-1].pack() 

then text entered user in widgets (inside write function):

texts = [] widget in self.widgets:     texts.append(widget.get()) 

Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -