title: referencing widgets from imported module
body: <p>I have 2 TkInter modules. One is toolbar module (tBar.py) and the second is a general module (tBarCall.py).</p>
  
  <p>1) the toolbar module (tBar.py): This will create a toolbar frame and place buttons (like save, add, delete etc.) on top of it.</p>
  
  <p>2) the client master module (tBarCall.py): This will import and run the toolbar module. Then at a later stage it should enable / disable some of the buttons placed on the toolbar frame. Please see the errors I am shown when I am trying to enable/ disable the buttons.</p>
  
  <p>I am able to import the toolbar module from inside the client master module, but I am not able to enable/ disable (reference) the buttons on the toolbar frame.</p>
  
  <p>Can you please help me how I can do this?</p>
  
  <p>Here is the code:</p>
  
  <p>===tBar.py===</p>
  
  <pre><code>import tkinter as tk
  
  def attach_toolbar(rootWindow, action, save_record, first_record):
      if action == "I":
          fToolbar = tk.Frame(rootWindow, padx = 1, pady = 1, bg="RED")
          fToolbar.grid(row=0, column = 0, sticky='w') #pack(anchor="nw",expand=1) #
          bSave = tk.Button(fToolbar, text="save", command=save_record)     #width=6, height=2, text = "Save\nrecord", font=("Calibri", 8), 
          bFirst = tk.Button(fToolbar, text="first", command=first_record)     #width=6, height=2, text = "First\nrecord", font=("Calibri", 8), 
  
          bSave.pack(side="left")
          bFirst.pack(side="left")
      else:
          bFirst.configure(state="disabled")
  </code></pre>
  
  <p>===tBarCall.py===</p>
  
  <pre><code>import tkinter as tk
  import tBar
  
  def save_record():
      print ("save_record")
  
  def first_record():
      print ("first_record")
  
  class startModule:
      def __init__(self, rootWindow):
          print("__init__")
  
          self.rootWindow = rootWindow
          self.rootClient = tk.Toplevel(self.rootWindow)
          self.rootClient.geometry('1300x650+1+1')
          tBar.attach_toolbar(self.rootClient, "I", save_record, first_record)
          #tBar.attach_toolbar(self.rootClient, "D", save_record, first_record) #UnboundLocalError: local variable 'bFirst' referenced before assignment
          #bFirst.configure(state="disabled") #NameError: name 'bFirst' is not defined        
          #self.rootClient.bFirst.configure(state="disabled") #AttributeError: 'Toplevel' object has no attribute 'bFirst'
          #self.rootClient.fToolbar.bFirst.configure(state="disabled") #AttributeError: 'Toplevel' object has no attribute 'fToolbar'
  
  if __name__ == "__main__":
      root = tk.Tk()
      startModule(root)
      root.mainloop()
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/RuSf6.gif" rel="nofollow noreferrer">Errorscr</a></p>