dimanche 22 octobre 2017

How to get a function to change what's in the parameter of a previous function?

Let's say I have a function like this:

def test_function(select):  
    function_test(testing)  

And a three radio buttons like this in tkinter:

selection = IntVar()
test1= Radiobutton(archive_buttons, text = 'Test Function', variable = selection, value = 1)
test2 = Radiobutton(archive_buttons, text = 'Test Function', variable = selection, value = 2)
test3 = Radiobutton(archive_buttons, text = 'Test Function', variable = selection, value = 3)

I'm trying to create a function like the one below. It attempts to change the what is in the parameter of function_test(testing) in the first function to one of the html options in the options list.

def select():
  options = ['hi.html', 'hello.html', 'hey.html'}
  counter = 1
  global testing
  for option in options:
    if selection.get() == options[counter]:
        testing = options[counter]
        counter = counter + 1
  return testing

So when i click a button like the one below on a tkinter GUI when a radio button is selected in the same GUI, I want it the parameter of function_test(testing) in the first function to be changed already beforehand (as a result of me selecting a radiobutton on my GUI).

extract_news_button = Button(function_buttons, text = 'Extract News', command = test_function, pady = 4)

However, I get this error:

line 15, in select
  return testing
 NameError: name 'testing' is not defined

How can I get this to work like I want it to?

Aucun commentaire:

Enregistrer un commentaire