title: etree findall not working inside function
body: <p>I am puzzled.
  I have written this little piece of code before and used it somewhere else:</p>
  
  <pre><code>def testBut(p):
      print(root)
      for items in root.findall("a/item"):
          print(items.get("name"))
  </code></pre>
  
  <p>and it has worked just fine.</p>
  
  <p>But now in my newer project i have the following code:</p>
  
  <pre><code>for items in root.findall("a/item"):
  print(items.get("name"))
  
  def testBut(p):
      print(root)
      for items in root.findall("a/item"):
          print(items.get("name"))
  </code></pre>
  
  <p>so OUTSIDE the def. it workes just fine, and shows me all the items in a, where as INSIDE the def i get nothing but root (because i print it). Can anyone explain why?</p>
  
  <p>i am sorry if this is a repost or whatever, but i simply cannot find an answer, especially given it works just fine in a different file but exact same setup.. </p>
  
  <p>edit: full(ish) code.</p>
  
  <pre><code>from tkinter import *
  from xml.etree.ElementTree import ElementTree
  from xml.etree.ElementTree import Element
  import xml.etree.ElementTree as ET
  
  tree = ET.parse("Alphabet.xml")
  root = tree.getroot()
  
  colour0 = "WHITE"
  colour1 = "OLIVEDRAB1"
  colour2 = "PALETURQUOISE1"
  colour3 = "ROSYBROWN1"
  font1 = "Arial, 24"
  counterRow = 1
  counterColumn = 0
  
  for items in root.findall("a/item"):
      print(items.get("name"))
  
  def testBut(p):
      print(root)
      for items in root.findall("a/item"):
          print("test")
          print(items.get("name"))
  
  def setup():
      for letters in root:
          global counterRow
          global counterColumn
  
          letters.tag = Button(vindue, text=letters.tag, font=font1,
                               command=lambda p=letters.tag: testBut(p))\
              .grid(row=counterRow, column=counterColumn, sticky="nsew")
          counterColumn += 1
          if counterColumn &gt; 7:
              counterRow += 1
              counterColumn = 0
  
  
  def reset():
      for buttons in vindue.grid_slaves():
          if buttons.grid_info()["row"] &gt; 0:
              buttons.grid_forget()
  
  
  def showBut(input):
      counter = 0
      reset()
      lst = []
      print(input)
      str = input+"/item"
      print(str)
      for items in root.findall("a/item"):
          print(items.get("name"))
          print("test")
          varstr = items.get("name")+"Var"
          varstr = IntVar()
          varstr2 = items.get("name")
          varstr2 = Button(vindue, text=items.get("name"), font="Arial, 44", command=lambda varstr=varstr: (varstr.set(varstr.get() + 1), print(varstr.get())))
          varstr2.grid(row=1, column=counter)
          counter += 1
  
  
  
  
  vindue = Tk()
  
  setup()
  
  vindue.mainloop()
  </code></pre>