0

I am using the following snippet of code adopted from here I need it to wait for the user to choose an option and then fill that into the rest of the code (to add to an xml file -a metadata generator program I am working on with details here)

from Tkinter import *

def print_it(event):
   print var.get()

root = Tk()
var = StringVar()
var.set("Set Copyright for: " + str(File))
OptionMenu(root, var, "Internal Use Only","Internal & Community Use","Whole Of Government Use", "Project Specific Licence","No licence constraints on ATGIS/TRC use", command=print_it).pack()
root.mainloop() 

should this be part of the def above?

for node in tree.findall('.//copyright'):
    node.text = str(var) # not sure how to call the output.
Community
  • 1
  • 1
GeorgeC
  • 956
  • 5
  • 16
  • 40
  • @Hoxieboy - Your comment got deleted (??). I don't want to use the def print_it -I wasn't quite clear why it was there in the original program and the script didn't work when it was commented out. I just want the script to ask the user for the input, put it into the xml file and then continue autofilling or asking other questions as needed. – GeorgeC Feb 02 '12 at 07:00

1 Answers1

1

You started the event loop with:

root.mainloop() 

Looks like you just need a place to exit the loop and do your other processing. For example, since the print_it process seems ideally placed you could modify it like so:

def print_it(event):
    print var.get()
    root.quit()

Now, whenever print_it is executed the mainloop is exited- whatever code is below "root.mainloop()" would be executed right away. So you could carry on from there...

Niall Byrne
  • 2,448
  • 1
  • 17
  • 18
  • Thanks mate...that was so simple. I really have to spend time learning the basics properly rather than just learning what's needed to get a job done. – GeorgeC Feb 02 '12 at 22:45