0

I want to update the cspray window with new radio buttons . But now the buttons gets overrited everytime the clicked_value function is called.

def clicked_value(self):
    if clicked.get()!="":
        for row in tree_caster_data.get_children():
            tree_caster_data.delete(row)
            cspray.update()
        #make tab from section ID
        tab_names = []
        for item in tree_caster_data.get_children():
            tab_names.append(tree_caster_data.item(item)['values'][0])
        var = StringVar()
        var.set(tab_names[0])
         radio_frame = Frame(cspray).grid(row=0, column=0)
        i=0
        for item in tab_names:
            button = Radiobutton(radio_frame, text=item, variable=var, value=item, command=lambda: sel())
            button.grid(row=0,column=i)
            i+=1

I have tried updating the window but it does not work. The main problem is that theradio buttons are created using the obtained list and the list values are to be generated inside the same function so I cannottake the radio button outside in order to use destroy function at the start of the function. Please help me in this. Thankyou so much in advance.

  • the solution would be to not create radio buttons inside of a function. except it looks like this is actually a method, so all you need to do is add it as an attribute for whatever class instance it is beign called from. – Alexander Feb 22 '23 at 04:41
  • Seems like the function is inside a class, then why don't you use class/instance variables instead of local variables? Another strange thing is that you destroy all items in the treeview before populating `tab_names` *using items in treeview*, so `tab_names` should always be empty list. – acw1668 Feb 22 '23 at 05:48
  • @acw1668 the list has been taken from database. I have truncated that part. The click only clears treeview data to insert new one – Prashant Priyadarshi Feb 22 '23 at 07:55
  • @Alexander I did not get your point. Are you saying to use class method for tracking the clicked value? can you show the sample of what youhave in your mind? could you please elaborate more – Prashant Priyadarshi Feb 22 '23 at 07:57

0 Answers0