Event triggered by Listbox and Radio button in python Tkinter -



Event triggered by Listbox and Radio button in python Tkinter -

i want create event triggered either alter in list box selected item or alter in radio button selected item. possible? utilize code:

def getscript(event): state = rb.get() listscript = [] processor = () processor = lb1.get(lb1.curselection()) if processor : if (state == 1): print processor if (state == 2): pass if (state == 3): pass frame2 = frame(top) frame2.pack(fill = x) rb = intvar() r1 = radiobutton(frame2, text = "parallel test", variable = rb, value = 1, command = getscript) r2 = radiobutton(frame2, text = "non parallel test", variable = rb, value = 2, command = getscript) r3 = radiobutton(frame2, text = "specific test", variable = rb, value = 3, command = getscript) r1.grid(row = 0, column = 0, padx = 10) r2.grid(row = 0, column = 1, padx = 10) r3.grid(row = 0, column = 2, padx = 10) frame3 = frame(top) frame3.pack(fill = x) space_frame3 = frame(frame3, width = 10) l5 = label(frame3, text = "processor unit") l6 = label(frame3, text = "script test") lb1 = listbox(frame3, height = 7, exportselection = 0) lb1.bind('<<listboxselect>>',getscript) scrollbar = scrollbar(frame3) lb2 = listbox(frame3, height = 7, width = 40, yscrollcommand = scrollbar.set, exportselection = 0)

everything goes fine long i've selected radiobutton before selecting item in listbox. every time select radio button, return:

typeerror: getscript() takes 1 argument (0 given)

what happen when select radiobutton :

1) intvar rb set button value

2) command getscript called.

but, radiobutton selection not generates event, that's why there 2 options in case :

call function using lambda function provide parameter command getscript expect 1 parameter ( that's error message ).

r1 = radiobutton(frame2, text = "parallel test", variable = rb, value = 1, command = lambda : getscript(none) )

an other alternative - seem aim know widget selected - utilize such command:

r1 = radiobutton(frame2, text = "parallel test", variable = rb, value = 1, command = lambda : getscript(r1) )

with getsript function takes widget. this:

def getsript(widget): print widget["text"]

python listbox tkinter radio-button eventhandler

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -