0

Here's the code highlighting the problem:

from tkinter import *
root= Tk()

def subwindow():
    top = Tk()

    s=IntVar()

    def clicked(value):
        myLabel3=Label(top,text=value)
        myLabel3.grid(row=4,column=1)

    Radiobutton(top, text="Option 1", variable=s, value=1).grid(row=1,column=1)
    Radiobutton(top, text="Option 2", variable=s, value=2).grid(row=2,column=1)
    Radiobutton(top, text="Option 3", variable=s, value=3).grid(row=3,column=1)
    myButton2 = Button(top, text="get",command=lambda: clicked(s.get()))
    myButton2.grid(row=4, column=2)

    top.mainloop()

r=IntVar()

def clicked(value):
    myLabel3=Label(root,text=value)
    myLabel3.grid(row=4,column=1)

Radiobutton(root, text="Option 1", variable=r, value=1).grid(row=1,column=1)
Radiobutton(root, text="Option 2", variable=r, value=2).grid(row=2,column=1)
Radiobutton(root, text="Option 3", variable=r, value=3).grid(row=3,column=1)
myButton2 = Button(root, text="get value",command=lambda: clicked(r.get()))
myButton2.grid(row=4, column=2)

myButton3 = Button(root, text="open subwindow",command=subwindow)
myButton3.grid(row=7, column=1)

root.mainloop()

I find that the r.get() works only in root and not in top. Hence the Radiobutton never gives me the value in top. I want the radio button to work in the subwindow just like it works in root. Any work-arounds?

0 Answers0