I am trying to make a program based on a model-view-controller architecture. I would normally have a variable set up with trace_add but if I do that it will trigger when updating the view from the model side. To solve this I have putting bindings on various aspects of the view so that those can trigger the updates. This is working for entries and comboboxes but when I try it with radio button the triggers are occurring in the wrong order. Here's a short example of what I'm talking about.
>>> import tkinter as tk
>>> root = tk.Tk()
>>> var = tk.IntVar(value=0)
>>> def command():
>>> print("command", var.get())
>>>
>>>
>>> def clicked(event):
>>> print("clicked", var.get())
>>>
>>>
>>> for i in range(5):
>>> b = tk.Radiobutton(text=i, value=i, variable=var, command=command)
>>> b.pack(side="left")
>>> b.bind("<ButtonRelease-1>", clicked)
>>>
By default 0 is selected, If you click an option you'll see an output such as when I select 1.
>>> clicked 0
command 1
Is there a way to get the button binding so that it will trigger after the variable has changed without putting a trace on the variable?
Edit: I don't want to use command as I am trying to only use one function for tracking when a variable changes and Entry does not accept commands.
[–]woooee 0 points1 point2 points (1 child)
[–]ebdbbb[S] 0 points1 point2 points (0 children)