python - Call a class function in one module from another -


i have problem updating textbox in gui. code looks following in principle:

    # static_textbox module     # -------------------------      class tp_textbox(tk.labelframe):           def __init__(self, master = none,bg='#000000'):              tk.labelframe.__init__(self, master,text = 'information')              self.grid(row = 0, column = 0, columnspan = 1,rowspan = 1,                        padx = 15, pady = 15,sticky = tk.n+tk.w + tk.s+tk.e)              self.create()           def create(self):                 self.v = tk.stringvar()             self.v.set('choose time interval , press "read data" button load data')             self.textbox = tk.label(self, textvariable = self.v,                                      anchor=tk.w, justify=tk.left, font=("arial", 10, 'bold'))             self.textbox.grid()                     print 'not again!!!!!!!!!!!!!!!!!!!!!!!!!!!'           def update_textbox(self,text):              self.v.set(text)             self.update_idletasks()                  # module calling static_textbox     # -----------------------------      import static_textbox      def createpickel(my_dir = u'/test_data',                       start = ['2012','1','2','12','45'],                      stop = ['2012','6','2','12','45'],                      filterval = "filtered",                      mydata = transpaper_dataholder.dataholder()):          update_info = static_textbox.tp_textbox()          infotext = 'locating data on server...'         update_info.update_textbox(infotext) 

i realize line "update_info = static_textbox.tp_textbox()" executes whole module including create function , creates new textbox on top old. want call update function in static_text module how done? i'm new object oriented programming...sorry stupid question.

edit:

after reading answer , comments below assume solution should following

create textbox object in main module , send "data holder" module:

# main module  import static_textbox import transpaper_dataholder      def __init__(self, root):     """ """         self.data = transpaper_dataholder.dataholder() #class holds data         tk.frame.__init__(self, root)         root.title(""" ferrybox tools """)         self._setupmainwindow()      def _setupmainwindow(self):         textobj = static_textbox.tp_textbox(root)         self.data.settextobj(textobj) 

a data holder module can call "update_textbox" function in textbox object:

# data holder module  class dataholder(object):          def settextobj(self,textobj):             self.textobj = textobj          def gettextobj(self):             return self.textobj 

the "update_textbox" called several different modules:

# typical call other modules         import transpaper_dataholder  def createpickel(my_dir = u'/test_data',           start = ['2012','1','2','12','45'],          stop = ['2012','6','2','12','45'],          filterval = "filtered",          mydata = transpaper_dataholder.dataholder()):        data = mydata      infotext = 'locating data on server...'     textobj = data.gettextobj()     textobj.update_textbox(infotext)     

this not work however..no errors textbox isn't updated. sugestions?

you cannot treat update_textbook static function since it's not declared static (and functionality implies receives object).

in python self parameter refers instance of class. therefor can use in case follows:

# create new text-book textbook = static_textbox.tp_textbox()  # update textbook text textbook.update_textbox("123") 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -