Python Tkinter Radiobutton narrowing user input
Question: I'm new to programming, python, and Tkinter and I wanted a nice solution
(maybe using state=DISABLED?) to limit the user's options based on the buttons
they select. My present code:

    
    
    from Tkinter import *
    
    master = Tk()
    
    def ok():
        master.destroy()  
    
    v1 = IntVar()
    v2 = IntVar()
    v3 = IntVar()
    v4 = IntVar()
    v5 = IntVar()
    
    Label(master, text="""Which Method do you want to run?""",justify = LEFT, padx = 20).pack()
    Radiobutton(master, text="Positive",padx = 20, variable=v1, value=1).pack(anchor=W)
    Radiobutton(master, text="Negative", padx = 20, variable=v1, value=2).pack(anchor=W)
    Radiobutton(master, text="Both", padx = 20, variable=v1, value=3).pack(anchor=W)
    
    Label(master, text="""Choose a tray type:""",justify = LEFT, padx = 20).pack()
    a1=Radiobutton(master, text="54",padx=20,variable=v2,value=1).pack(anchor=W)
    a2=Radiobutton(master, text="96",padx = 20, variable=v2, value=2).pack(anchor=W)
    
    Label(master, text="""Sort by columns(default) or rows?""",justify = LEFT, padx = 20).pack()
    b1=Radiobutton(master, text="columns",padx=20,variable=v3,value=1).pack(anchor=W)
    b2=Radiobutton(master, text="rows",padx = 20, variable=v3, value=2).pack(anchor=W)
    
    Label(master, text="""Choose a tray number:""",justify = LEFT, padx = 20).pack()
    c1=Radiobutton(master, text="Stk1-01",padx = 20, variable=v4, value=1).pack(anchor=W)
    c2=Radiobutton(master, text="Stk1-02", padx = 20, variable=v4, value=2).pack(anchor=W)
    c3=Radiobutton(master, text="Stk1-03",padx = 20, variable=v4, value=3).pack(anchor=W)
    c4=Radiobutton(master, text="Stk1-04", padx = 20, variable=v4, value=4).pack(anchor=W)
    c5=Radiobutton(master, text="MT1-Frnt",padx = 20, variable=v4, value=5).pack(anchor=W)
    
    c6=Radiobutton(master, text="MT1-Rear", padx = 20, variable=v4, value=6).pack(anchor=W)
    c7=Radiobutton(master, text="MT2-Frnt",padx = 20, variable=v4, value=7).pack(anchor=W)
    c8=Radiobutton(master, text="MT2-Rear", padx = 20, variable=v4, value=8).pack(anchor=W)
    
    
    Label(master, text="""Would you like to insert a midpoint standard and blank?""",justify = LEFT, padx = 20).pack()
    Radiobutton(master, text="Yes",padx = 20, variable=v5, value=1).pack(anchor=W)
    Radiobutton(master, text="No", padx = 20, variable=v5, value=2).pack(anchor=W)
    
    Button(master, text="OK", command=ok).pack()
    
    master.mainloop()
    

I want a way so that if a1 is selected, c6 through c8 are not able to be
selected by the user. Similarly, if a1 is selected, the user would not be able
to select either b1 or b2. There's probably a way to use sample=DISABLED to
grey out the unselectable answers or maybe use a function to make the options
appear once a value is selected. Any help is appreciated!


Answer: I made some significant albeit easy changes to your sample code here simply to
make things more accessible.

I've wrapped all of the Widgets into a class to have better access to them
within functions. Basically what you want is simply a callback function on any
change of a1 and a2 that will disable c6-8 if 1, else enable them.

I also had to make some of your pack statements happen on a seperate line as
`Radiobutton(...).pack()` will return `None` and make `self.someRadiobutton`'s
`config` inaccessible.

Here is the code so you can see what I mean.

    
    
    from Tkinter import *
    
    class Window():
    
        def __init__(self, master):
    
            self.master = master
            self.v1 = IntVar()
            self.v2 = IntVar()
            self.v3 = IntVar()
            self.v4 = IntVar()
            self.v5 = IntVar()
    
            Label(master, text="""Which Method do you want to run?""",justify = LEFT, padx = 20).pack()
            Radiobutton(master, text="Positive",padx = 20, variable=self.v1, value=1).pack(anchor=W)
            Radiobutton(master, text="Negative", padx = 20, variable=self.v1, value=2).pack(anchor=W)
            Radiobutton(master, text="Both", padx = 20, variable=self.v1, value=3).pack(anchor=W)
    
            Label(master, text="""Choose a tray type:""",justify = LEFT, padx = 20).pack()
            self.a1=Radiobutton(master, text="54",padx=20,variable=self.v2,value=1, command = self.disable).pack(anchor=W)
            self.a2=Radiobutton(master, text="96",padx = 20, variable=self.v2, value=2, command = self.disable).pack(anchor=W)
    
            Label(master, text="""Sort by columns(default) or rows?""",justify = LEFT, padx = 20).pack()
            self.b1=Radiobutton(master, text="columns",padx=20,variable=self.v3,value=1)
            self.b1.pack(anchor=W)
            self.b2=Radiobutton(master, text="rows",padx = 20, variable=self.v3, value=2)
            self.b2.pack(anchor=W)
    
            Label(master, text="""Choose a tray number:""",justify = LEFT, padx = 20).pack()
            self.c1=Radiobutton(master, text="Stk1-01",padx = 20, variable=self.v4, value=1).pack(anchor=W)
            self.c2=Radiobutton(master, text="Stk1-02", padx = 20, variable=self.v4, value=2).pack(anchor=W)
            self.c3=Radiobutton(master, text="Stk1-03",padx = 20, variable=self.v4, value=3).pack(anchor=W)
            self.c4=Radiobutton(master, text="Stk1-04", padx = 20, variable=self.v4, value=4).pack(anchor=W)
            self.c5=Radiobutton(master, text="MT1-Frnt",padx = 20, variable=self.v4, value=5).pack(anchor=W)
    
            self.c6=Radiobutton(master, text="MT1-Rear", padx = 20, variable=self.v4, value=6)
            self.c6.pack(anchor=W)
            self.c7=Radiobutton(master, text="MT2-Frnt",padx = 20, variable=self.v4, value=7)
            self.c7.pack(anchor=W)
            self.c8=Radiobutton(master, text="MT2-Rear", padx = 20, variable=self.v4, value=8)
            self.c8.pack(anchor=W)
    
    
            Label(master, text="""Would you like to insert a midpoint standard and blank?""",justify = LEFT, padx = 20).pack()
            Radiobutton(master, text="Yes",padx = 20, variable=self.v5, value=1).pack(anchor=W)
            Radiobutton(master, text="No", padx = 20, variable=self.v5, value=2).pack(anchor=W)
    
            Button(master, text="OK", command=self.ok).pack()
    
        def ok(self):
            self.master.destroy() 
    
        def disable(self):
    
            if self.v2.get() == 1:
                self.b1.config(state = 'disabled')
                self.b2.config(state = 'disabled')
                self.c6.config(state = 'disabled')
                self.c7.config(state = 'disabled')
                self.c8.config(state = 'disabled')
    
            else:
                self.b1.config(state = 'normal')
                self.b2.config(state = 'normal')
                self.c6.config(state = 'normal')
                self.c7.config(state = 'normal')
                self.c8.config(state = 'normal')
    
    master = Tk()
    w = Window(master)
    master.mainloop()
    

If you wanted to do this without using a class you would have to pass a
reference to the relevant `Radiobuttons` and `IntVars` to the `disable`
function. If you would like to see how just let me know in a comment.

