title: Adding tabs to a Notebook at runtiime with a function - I can create the tab and its inner frame, but cannot add components to the frame
body: <p>I am starting with a notebook defined in the original code as having 4 tabs, each of which has an associated Frame (Tab1 has a Frame named page1, Tab2 has page2, and so on). for the first two tabs, I have functions that place a canvas in each frame and draw a graph on that canvas. So I can place items on these pre-defined tab pages at runtime in code.</p>
  <p>My goal is to be able to place additional, unplanned tabs into the notebook, using functions, and then place information on the pages associated with the new tabs.</p>
  <p>I have a function Command3() - see below - in which I create the tab on the fly.</p>
  <p>'''</p>
  <pre><code>def command3():
      #command invoked by button 3 - add a tab to the notebook
      tab_caption = simpledialog.askstring('Tab Text','Enter Text for Tab')
      ntn = len(nb.tabs()) + 1
      if tab_caption == '':
          tab_caption = 'Tab ' + str(ntn)
      var_name = 'page' + str(ntn)
      command_string = var_name + ' = tk.Frame(nb)'
      exec(command_string)
      command_string = 'nb.add('+var_name+', text = tab_caption)'
      exec(command_string)
  </code></pre>
  <p>'''</p>
  <p>The above code works just fine. When I execute this code (by clicking on Button3) I get a new tab with the text I supply in the dialog box which has an inner frame named &quot;page 5&quot;. I can click on the tab and select it (it shows nothing because I haven't put anything there), and I can even change the name of the tab in code.</p>
  <p>My problem is that, when I try to place anything on &quot;page 5&quot; nothing appears. The function Command4 below is intended to just place a label anywhere on the page.</p>
  <p>'''</p>
  <pre><code> def command4():
  
      #command invoked by button 4 - add label
      last_tab = len(nb.tabs())
      last_tab_index = last_tab-1
      page_name = 'page' + str(last_tab)
      nb.tab(last_tab_index, text = 'Repeat Graph')
      print(last_tab)
      print(last_tab_index)
      print(page_name)
  
      labelTest = tk.Label(page5, text = 'Something')
      labelTest.pack()
  </code></pre>
  <p>'''
  When this code executes, the tab name changes, the print statements all work, and the last two lines appear to execute without error, but nothing appears in the frame for Tab5 (Frame is page5).</p>
  <p>Python seems to know that page 5 exists (when I terminate the program and type &gt;&gt;&gt; page 5 in Idle, I get &lt;tkinter.Frame object .!frame2.!notebook.!frame5&gt;. So command 3 seems to have worked and created the appropriate Frame object.</p>
  <p>My intent was to compute the &quot;page&quot; name so I could do this repeatedly and use code as follows:</p>
  <p>'''</p>
  <pre><code> def command4():
  
      #command invoked by button 4 - add label
      last_tab = len(nb.tabs())
      last_tab_index = last_tab-1
      page_name = 'page' + str(last_tab)
      nb.tab(last_tab_index, text = 'Repeat Graph')
      print(last_tab)
      print(last_tab_index)
      print(page_name)
  
      command_string = &quot;labelTest = tk.Label(&quot; + page_name + &quot;, text = 'Something')&quot;
      exec(command_string) 
      labelTest.pack()
  </code></pre>
  <p>'''</p>
  <p>When I execute this code, the exec(command_string) produces no errors, but, when the software executes the labelTest.pack() command, I get an error that the name labelTest is not defined.</p>
  <p>Is this a scope problem? Is there another way to handle this problem? Is there some way to use the internal &quot;.!frame2.!notebook.!frame5&quot; notation to accomplish the same thing?</p>