FAQ
Hi!
What I'm missing in following code? Cannot get the values of
radiobuttons. Starting only one class (GetVariant), it works. When I put
two classes together, it doesn't.
Regards, VK

from Tkinter import *
class GetVariant:
def __init__(self):
self.root = Tk()
self.mainframe = Frame(self.root,bg="yellow")
self.mainframe.pack(fill=BOTH,expand=1)

self.firstframe = Frame(self.mainframe,bg="red")
self.firstframe.pack(side=BOTTOM,expand=1)

global v
v = StringVar()
self.radiobutton = Radiobutton(self.firstframe,text= "Variant
1", variable=v, value="Variant 1")
self.radiobutton.pack(side=TOP,anchor=W)
self.radiobutton.select()
self.radiobutton = Radiobutton(self.firstframe,text= "Variant
2", variable=v, value="Variant 2")
self.radiobutton.pack(side=TOP,anchor=W)
self.radiobutton = Radiobutton(self.firstframe,text= "Variant
3", variable=v, value="Variant 3")
self.radiobutton.pack(side=TOP,anchor=W)



self.secondframe = Frame(self.mainframe,bg="blue")
self.secondframe.pack()
self.var = Button(self.secondframe,text="What
Variant",command=self.call)
self.var.pack(expand=1,side=BOTTOM)



def call(self):
self.variant = v.get()
print 'Input => "%s"' % self.variant

class OneButton:
def __init__(self):
self.root = Tk()
Button(self.root,text="click me",command=self.getvar).pack()
def getvar(self):
a=GetVariant()

d = OneButton()
d.root.mainloop()

Search Discussions

  • Philippe C. Martin at May 28, 2005 at 9:07 pm
    Hi,

    I think your second call to Tk() does it: this works although the look is
    different:


    from Tkinter import *
    class GetVariant:
    def __init__(self):
    self.root = Tk()
    self.mainframe = Frame(self.root,bg="yellow")
    self.mainframe.pack(fill=BOTH,expand=1)

    self.firstframe = Frame(self.mainframe,bg="red")
    self.firstframe.pack(side=BOTTOM,expand=1)

    global v
    v = StringVar()
    self.radiobutton = Radiobutton(self.firstframe,text= "Variant
    1", variable=v, value="Variant 1")
    self.radiobutton.pack(side=TOP,anchor=W)
    self.radiobutton.select()
    self.radiobutton = Radiobutton(self.firstframe,text= "Variant
    2", variable=v, value="Variant 2")
    self.radiobutton.pack(side=TOP,anchor=W)
    self.radiobutton = Radiobutton(self.firstframe,text= "Variant
    3", variable=v, value="Variant 3")
    self.radiobutton.pack(side=TOP,anchor=W)



    self.secondframe = Frame(self.mainframe,bg="blue")
    self.secondframe.pack()
    self.var = Button(self.secondframe,text="What
    Variant",command=self.call)
    self.var.pack(expand=1,side=BOTTOM)



    def call(self):
    self.variant = v.get()
    print 'Input => "%s"' % self.variant

    class OneButton:
    def __init__(self):
    self.root = Tk()
    Button(self.root,text="click me",command=self.getvar).pack()
    def getvar(self):
    a=GetVariant()

    d = OneButton()
    d.root.mainloop()




    VK wrote:
    Hi!
    What I'm missing in following code? Cannot get the values of
    radiobuttons. Starting only one class (GetVariant), it works. When I put
    two classes together, it doesn't.
    Regards, VK

    from Tkinter import *
    class GetVariant:
    def __init__(self):
    self.root = Tk()
    self.mainframe = Frame(self.root,bg="yellow")
    self.mainframe.pack(fill=BOTH,expand=1)

    self.firstframe = Frame(self.mainframe,bg="red")
    self.firstframe.pack(side=BOTTOM,expand=1)

    global v
    v = StringVar()
    self.radiobutton = Radiobutton(self.firstframe,text= "Variant
    1", variable=v, value="Variant 1")
    self.radiobutton.pack(side=TOP,anchor=W)
    self.radiobutton.select()
    self.radiobutton = Radiobutton(self.firstframe,text= "Variant
    2", variable=v, value="Variant 2")
    self.radiobutton.pack(side=TOP,anchor=W)
    self.radiobutton = Radiobutton(self.firstframe,text= "Variant
    3", variable=v, value="Variant 3")
    self.radiobutton.pack(side=TOP,anchor=W)



    self.secondframe = Frame(self.mainframe,bg="blue")
    self.secondframe.pack()
    self.var = Button(self.secondframe,text="What
    Variant",command=self.call)
    self.var.pack(expand=1,side=BOTTOM)



    def call(self):
    self.variant = v.get()
    print 'Input => "%s"' % self.variant

    class OneButton:
    def __init__(self):
    self.root = Tk()
    Button(self.root,text="click me",command=self.getvar).pack()
    def getvar(self):
    a=GetVariant()

    d = OneButton()
    d.root.mainloop()
  • Philippe C. Martin at May 28, 2005 at 9:10 pm
    Sorry,

    I still had your code in my clipboard :-) here goes:



    from Tkinter import *
    class GetVariant(Frame):
    def __init__(self,p):
    self.root = p
    self.mainframe = Frame(self.root,bg="yellow")
    self.mainframe.pack(fill=BOTH,expand=1)

    self.firstframe = Frame(self.mainframe,bg="red")
    self.firstframe.pack(side=BOTTOM,expand=1)


    self.v = StringVar()
    self.radiobutton = Radiobutton(self.firstframe,text="Variant 1",
    variable=self.v, value="Variant 1")
    self.radiobutton.pack(side=TOP,anchor=W)
    self.radiobutton.select()
    self.radiobutton = Radiobutton(self.firstframe,text="Variant 2",
    variable=self.v, value="Variant 2")
    self.radiobutton.pack(side=TOP,anchor=W)
    self.radiobutton = Radiobutton(self.firstframe,text="Variant 3",
    variable=self.v, value="Variant 3")
    self.radiobutton.pack(side=TOP,anchor=W)



    self.secondframe = Frame(self.mainframe,bg="blue")
    self.secondframe.pack()
    self.var = Button(self.secondframe,text="What
    Variant",command=self.call)
    self.var.pack(expand=1,side=BOTTOM)



    def call(self):
    print dir(self.v)
    self.variant = self.v.get()
    print 'Input => "%s"' % self.variant

    class OneButton(Frame):
    def __init__(self):
    self.root = Tk()
    Button(self.root,text="click me",command=self.getvar).pack()
    def getvar(self):
    print 'HRE'
    a=GetVariant(self.root)

    d = OneButton()
    d.root.mainloop()






    Philippe C. Martin wrote:
    Hi,

    I think your second call to Tk() does it: this works although the look is
    different:


    from Tkinter import *
    class GetVariant:
    def __init__(self):
    self.root = Tk()
    self.mainframe = Frame(self.root,bg="yellow")
    self.mainframe.pack(fill=BOTH,expand=1)

    self.firstframe = Frame(self.mainframe,bg="red")
    self.firstframe.pack(side=BOTTOM,expand=1)

    global v
    v = StringVar()
    self.radiobutton = Radiobutton(self.firstframe,text= "Variant
    1", variable=v, value="Variant 1")
    self.radiobutton.pack(side=TOP,anchor=W)
    self.radiobutton.select()
    self.radiobutton = Radiobutton(self.firstframe,text= "Variant
    2", variable=v, value="Variant 2")
    self.radiobutton.pack(side=TOP,anchor=W)
    self.radiobutton = Radiobutton(self.firstframe,text= "Variant
    3", variable=v, value="Variant 3")
    self.radiobutton.pack(side=TOP,anchor=W)



    self.secondframe = Frame(self.mainframe,bg="blue")
    self.secondframe.pack()
    self.var = Button(self.secondframe,text="What
    Variant",command=self.call)
    self.var.pack(expand=1,side=BOTTOM)



    def call(self):
    self.variant = v.get()
    print 'Input => "%s"' % self.variant

    class OneButton:
    def __init__(self):
    self.root = Tk()
    Button(self.root,text="click me",command=self.getvar).pack()
    def getvar(self):
    a=GetVariant()

    d = OneButton()
    d.root.mainloop()




    VK wrote:
    Hi!
    What I'm missing in following code? Cannot get the values of
    radiobuttons. Starting only one class (GetVariant), it works. When I put
    two classes together, it doesn't.
    Regards, VK

    from Tkinter import *
    class GetVariant:
    def __init__(self):
    self.root = Tk()
    self.mainframe = Frame(self.root,bg="yellow")
    self.mainframe.pack(fill=BOTH,expand=1)

    self.firstframe = Frame(self.mainframe,bg="red")
    self.firstframe.pack(side=BOTTOM,expand=1)

    global v
    v = StringVar()
    self.radiobutton = Radiobutton(self.firstframe,text= "Variant
    1", variable=v, value="Variant 1")
    self.radiobutton.pack(side=TOP,anchor=W)
    self.radiobutton.select()
    self.radiobutton = Radiobutton(self.firstframe,text= "Variant
    2", variable=v, value="Variant 2")
    self.radiobutton.pack(side=TOP,anchor=W)
    self.radiobutton = Radiobutton(self.firstframe,text= "Variant
    3", variable=v, value="Variant 3")
    self.radiobutton.pack(side=TOP,anchor=W)



    self.secondframe = Frame(self.mainframe,bg="blue")
    self.secondframe.pack()
    self.var = Button(self.secondframe,text="What
    Variant",command=self.call)
    self.var.pack(expand=1,side=BOTTOM)



    def call(self):
    self.variant = v.get()
    print 'Input => "%s"' % self.variant

    class OneButton:
    def __init__(self):
    self.root = Tk()
    Button(self.root,text="click me",command=self.getvar).pack()
    def getvar(self):
    a=GetVariant()

    d = OneButton()
    d.root.mainloop()
  • VK at May 28, 2005 at 9:42 pm

    Philippe C. Martin wrote:
    Sorry,

    I still had your code in my clipboard :-) here goes:
    So, your code works, but I need, that first window calls another
    separate window. In your programm they stick together.
    Reg, VK


    from Tkinter import *
    class GetVariant(Frame):
    def __init__(self,p):
    self.root = p
    self.mainframe = Frame(self.root,bg="yellow")
    self.mainframe.pack(fill=BOTH,expand=1)

    self.firstframe = Frame(self.mainframe,bg="red")
    self.firstframe.pack(side=BOTTOM,expand=1)


    self.v = StringVar()
    self.radiobutton = Radiobutton(self.firstframe,text="Variant 1",
    variable=self.v, value="Variant 1")
    self.radiobutton.pack(side=TOP,anchor=W)
    self.radiobutton.select()
    self.radiobutton = Radiobutton(self.firstframe,text="Variant 2",
    variable=self.v, value="Variant 2")
    self.radiobutton.pack(side=TOP,anchor=W)
    self.radiobutton = Radiobutton(self.firstframe,text="Variant 3",
    variable=self.v, value="Variant 3")
    self.radiobutton.pack(side=TOP,anchor=W)



    self.secondframe = Frame(self.mainframe,bg="blue")
    self.secondframe.pack()
    self.var = Button(self.secondframe,text="What
    Variant",command=self.call)
    self.var.pack(expand=1,side=BOTTOM)



    def call(self):
    print dir(self.v)
    self.variant = self.v.get()
    print 'Input => "%s"' % self.variant

    class OneButton(Frame):
    def __init__(self):
    self.root = Tk()
    Button(self.root,text="click me",command=self.getvar).pack()
    def getvar(self):
    print 'HRE'
    a=GetVariant(self.root)

    d = OneButton()
    d.root.mainloop()






    Philippe C. Martin wrote:

    Hi,

    I think your second call to Tk() does it: this works although the look is
    different:


    from Tkinter import *
    class GetVariant:
    def __init__(self):
    self.root = Tk()
    self.mainframe = Frame(self.root,bg="yellow")
    self.mainframe.pack(fill=BOTH,expand=1)

    self.firstframe = Frame(self.mainframe,bg="red")
    self.firstframe.pack(side=BOTTOM,expand=1)

    global v
    v = StringVar()
    self.radiobutton = Radiobutton(self.firstframe,text= "Variant
    1", variable=v, value="Variant 1")
    self.radiobutton.pack(side=TOP,anchor=W)
    self.radiobutton.select()
    self.radiobutton = Radiobutton(self.firstframe,text= "Variant
    2", variable=v, value="Variant 2")
    self.radiobutton.pack(side=TOP,anchor=W)
    self.radiobutton = Radiobutton(self.firstframe,text= "Variant
    3", variable=v, value="Variant 3")
    self.radiobutton.pack(side=TOP,anchor=W)



    self.secondframe = Frame(self.mainframe,bg="blue")
    self.secondframe.pack()
    self.var = Button(self.secondframe,text="What
    Variant",command=self.call)
    self.var.pack(expand=1,side=BOTTOM)



    def call(self):
    self.variant = v.get()
    print 'Input => "%s"' % self.variant

    class OneButton:
    def __init__(self):
    self.root = Tk()
    Button(self.root,text="click me",command=self.getvar).pack()
    def getvar(self):
    a=GetVariant()

    d = OneButton()
    d.root.mainloop()




    VK wrote:

    Hi!
    What I'm missing in following code? Cannot get the values of
    radiobuttons. Starting only one class (GetVariant), it works. When I put
    two classes together, it doesn't.
    Regards, VK

    from Tkinter import *
    class GetVariant:
    def __init__(self):
    self.root = Tk()
    self.mainframe = Frame(self.root,bg="yellow")
    self.mainframe.pack(fill=BOTH,expand=1)

    self.firstframe = Frame(self.mainframe,bg="red")
    self.firstframe.pack(side=BOTTOM,expand=1)

    global v
    v = StringVar()
    self.radiobutton = Radiobutton(self.firstframe,text= "Variant
    1", variable=v, value="Variant 1")
    self.radiobutton.pack(side=TOP,anchor=W)
    self.radiobutton.select()
    self.radiobutton = Radiobutton(self.firstframe,text= "Variant
    2", variable=v, value="Variant 2")
    self.radiobutton.pack(side=TOP,anchor=W)
    self.radiobutton = Radiobutton(self.firstframe,text= "Variant
    3", variable=v, value="Variant 3")
    self.radiobutton.pack(side=TOP,anchor=W)



    self.secondframe = Frame(self.mainframe,bg="blue")
    self.secondframe.pack()
    self.var = Button(self.secondframe,text="What
    Variant",command=self.call)
    self.var.pack(expand=1,side=BOTTOM)



    def call(self):
    self.variant = v.get()
    print 'Input => "%s"' % self.variant

    class OneButton:
    def __init__(self):
    self.root = Tk()
    Button(self.root,text="click me",command=self.getvar).pack()
    def getvar(self):
    a=GetVariant()

    d = OneButton()
    d.root.mainloop()
  • Philippe C. Martin at May 28, 2005 at 10:19 pm
    Then I guess you need a TopLevel widget instead:


    (I still suggest you look at wxPython)


    from Tkinter import *
    class GetVariant:
    def __init__(self,p):
    self.root = p

    self.firstframe = Frame(self.root,bg="red")
    self.firstframe.pack(side=BOTTOM,expand=1)


    self.v = StringVar()
    self.radiobutton = Radiobutton(self.firstframe,text="Variant 1",
    variable=self.v, value="Variant 1")
    self.radiobutton.pack(side=TOP,anchor=W)
    self.radiobutton.select()
    self.radiobutton = Radiobutton(self.firstframe,text="Variant 2",
    variable=self.v, value="Variant 2")
    self.radiobutton.pack(side=TOP,anchor=W)
    self.radiobutton = Radiobutton(self.firstframe,text="Variant 3",
    variable=self.v, value="Variant 3")
    self.radiobutton.pack(side=TOP,anchor=W)



    self.secondframe = Frame(self.root,bg="blue")
    self.secondframe.pack()
    self.var = Button(self.secondframe,text="What
    Variant",command=self.call)
    self.var.pack(expand=1,side=BOTTOM)



    def call(self):
    self.variant = self.v.get()
    print 'Input => "%s"' % self.variant

    class OneButton:
    def __init__(self):
    self.root = Tk()
    Button(self.root,text="click me",command=self.getvar).pack()
    def getvar(self):
    self.mainframe = Toplevel(bg="yellow")
    a=GetVariant(self.mainframe)

    d = OneButton()
    d.root.mainloop()

    VK wrote:
    Philippe C. Martin wrote:
    Sorry,

    I still had your code in my clipboard :-) here goes:
    So, your code works, but I need, that first window calls another
    separate window. In your programm they stick together.
    Reg, VK


    from Tkinter import *
    class GetVariant(Frame):
    def __init__(self,p):
    self.root = p
    self.mainframe = Frame(self.root,bg="yellow")
    self.mainframe.pack(fill=BOTH,expand=1)

    self.firstframe = Frame(self.mainframe,bg="red")
    self.firstframe.pack(side=BOTTOM,expand=1)


    self.v = StringVar()
    self.radiobutton = Radiobutton(self.firstframe,text="Variant 1",
    variable=self.v, value="Variant 1")
    self.radiobutton.pack(side=TOP,anchor=W)
    self.radiobutton.select()
    self.radiobutton = Radiobutton(self.firstframe,text="Variant 2",
    variable=self.v, value="Variant 2")
    self.radiobutton.pack(side=TOP,anchor=W)
    self.radiobutton = Radiobutton(self.firstframe,text="Variant 3",
    variable=self.v, value="Variant 3")
    self.radiobutton.pack(side=TOP,anchor=W)



    self.secondframe = Frame(self.mainframe,bg="blue")
    self.secondframe.pack()
    self.var = Button(self.secondframe,text="What
    Variant",command=self.call)
    self.var.pack(expand=1,side=BOTTOM)



    def call(self):
    print dir(self.v)
    self.variant = self.v.get()
    print 'Input => "%s"' % self.variant

    class OneButton(Frame):
    def __init__(self):
    self.root = Tk()
    Button(self.root,text="click me",command=self.getvar).pack()
    def getvar(self):
    print 'HRE'
    a=GetVariant(self.root)

    d = OneButton()
    d.root.mainloop()






    Philippe C. Martin wrote:

    Hi,

    I think your second call to Tk() does it: this works although the look is
    different:


    from Tkinter import *
    class GetVariant:
    def __init__(self):
    self.root = Tk()
    self.mainframe = Frame(self.root,bg="yellow")
    self.mainframe.pack(fill=BOTH,expand=1)

    self.firstframe = Frame(self.mainframe,bg="red")
    self.firstframe.pack(side=BOTTOM,expand=1)

    global v
    v = StringVar()
    self.radiobutton = Radiobutton(self.firstframe,text= "Variant
    1", variable=v, value="Variant 1")
    self.radiobutton.pack(side=TOP,anchor=W)
    self.radiobutton.select()
    self.radiobutton = Radiobutton(self.firstframe,text= "Variant
    2", variable=v, value="Variant 2")
    self.radiobutton.pack(side=TOP,anchor=W)
    self.radiobutton = Radiobutton(self.firstframe,text= "Variant
    3", variable=v, value="Variant 3")
    self.radiobutton.pack(side=TOP,anchor=W)



    self.secondframe = Frame(self.mainframe,bg="blue")
    self.secondframe.pack()
    self.var = Button(self.secondframe,text="What
    Variant",command=self.call)
    self.var.pack(expand=1,side=BOTTOM)



    def call(self):
    self.variant = v.get()
    print 'Input => "%s"' % self.variant

    class OneButton:
    def __init__(self):
    self.root = Tk()
    Button(self.root,text="click me",command=self.getvar).pack()
    def getvar(self):
    a=GetVariant()

    d = OneButton()
    d.root.mainloop()




    VK wrote:

    Hi!
    What I'm missing in following code? Cannot get the values of
    radiobuttons. Starting only one class (GetVariant), it works. When I put
    two classes together, it doesn't.
    Regards, VK

    from Tkinter import *
    class GetVariant:
    def __init__(self):
    self.root = Tk()
    self.mainframe = Frame(self.root,bg="yellow")
    self.mainframe.pack(fill=BOTH,expand=1)

    self.firstframe = Frame(self.mainframe,bg="red")
    self.firstframe.pack(side=BOTTOM,expand=1)

    global v
    v = StringVar()
    self.radiobutton = Radiobutton(self.firstframe,text= "Variant
    1", variable=v, value="Variant 1")
    self.radiobutton.pack(side=TOP,anchor=W)
    self.radiobutton.select()
    self.radiobutton = Radiobutton(self.firstframe,text= "Variant
    2", variable=v, value="Variant 2")
    self.radiobutton.pack(side=TOP,anchor=W)
    self.radiobutton = Radiobutton(self.firstframe,text= "Variant
    3", variable=v, value="Variant 3")
    self.radiobutton.pack(side=TOP,anchor=W)



    self.secondframe = Frame(self.mainframe,bg="blue")
    self.secondframe.pack()
    self.var = Button(self.secondframe,text="What
    Variant",command=self.call)
    self.var.pack(expand=1,side=BOTTOM)



    def call(self):
    self.variant = v.get()
    print 'Input => "%s"' % self.variant

    class OneButton:
    def __init__(self):
    self.root = Tk()
    Button(self.root,text="click
    me",command=self.getvar).pack()
    def getvar(self):
    a=GetVariant()

    d = OneButton()
    d.root.mainloop()
  • VK at May 28, 2005 at 11:10 pm

    Philippe C. Martin wrote:
    Then I guess you need a TopLevel widget instead:


    (I still suggest you look at wxPython)


    from Tkinter import *
    class GetVariant:
    def __init__(self,p):
    self.root = p

    self.firstframe = Frame(self.root,bg="red")
    self.firstframe.pack(side=BOTTOM,expand=1)


    self.v = StringVar()
    self.radiobutton = Radiobutton(self.firstframe,text="Variant 1",
    variable=self.v, value="Variant 1")
    self.radiobutton.pack(side=TOP,anchor=W)
    self.radiobutton.select()
    self.radiobutton = Radiobutton(self.firstframe,text="Variant 2",
    variable=self.v, value="Variant 2")
    self.radiobutton.pack(side=TOP,anchor=W)
    self.radiobutton = Radiobutton(self.firstframe,text="Variant 3",
    variable=self.v, value="Variant 3")
    self.radiobutton.pack(side=TOP,anchor=W)



    self.secondframe = Frame(self.root,bg="blue")
    self.secondframe.pack()
    self.var = Button(self.secondframe,text="What
    Variant",command=self.call)
    self.var.pack(expand=1,side=BOTTOM)



    def call(self):
    self.variant = self.v.get()
    print 'Input => "%s"' % self.variant

    class OneButton:
    def __init__(self):
    self.root = Tk()
    Button(self.root,text="click me",command=self.getvar).pack()
    def getvar(self):
    self.mainframe = Toplevel(bg="yellow")
    a=GetVariant(self.mainframe)

    d = OneButton()
    d.root.mainloop()

    VK wrote:

    Philippe C. Martin wrote:
    Sorry,

    I still had your code in my clipboard :-) here goes:
    So, your code works, but I need, that first window calls another
    separate window. In your programm they stick together.
    Reg, VK


    from Tkinter import *
    class GetVariant(Frame):
    def __init__(self,p):
    self.root = p
    self.mainframe = Frame(self.root,bg="yellow")
    self.mainframe.pack(fill=BOTH,expand=1)

    self.firstframe = Frame(self.mainframe,bg="red")
    self.firstframe.pack(side=BOTTOM,expand=1)


    self.v = StringVar()
    self.radiobutton = Radiobutton(self.firstframe,text="Variant 1",
    variable=self.v, value="Variant 1")
    self.radiobutton.pack(side=TOP,anchor=W)
    self.radiobutton.select()
    self.radiobutton = Radiobutton(self.firstframe,text="Variant 2",
    variable=self.v, value="Variant 2")
    self.radiobutton.pack(side=TOP,anchor=W)
    self.radiobutton = Radiobutton(self.firstframe,text="Variant 3",
    variable=self.v, value="Variant 3")
    self.radiobutton.pack(side=TOP,anchor=W)



    self.secondframe = Frame(self.mainframe,bg="blue")
    self.secondframe.pack()
    self.var = Button(self.secondframe,text="What
    Variant",command=self.call)
    self.var.pack(expand=1,side=BOTTOM)



    def call(self):
    print dir(self.v)
    self.variant = self.v.get()
    print 'Input => "%s"' % self.variant

    class OneButton(Frame):
    def __init__(self):
    self.root = Tk()
    Button(self.root,text="click me",command=self.getvar).pack()
    def getvar(self):
    print 'HRE'
    a=GetVariant(self.root)

    d = OneButton()
    d.root.mainloop()






    Philippe C. Martin wrote:


    Hi,

    I think your second call to Tk() does it: this works although the look is
    different:

    from Tkinter import *
    class GetVariant:
    def __init__(self):
    self.root = Tk()
    self.mainframe = Frame(self.root,bg="yellow")
    self.mainframe.pack(fill=BOTH,expand=1)

    self.firstframe = Frame(self.mainframe,bg="red")
    self.firstframe.pack(side=BOTTOM,expand=1)

    global v
    v = StringVar()
    self.radiobutton = Radiobutton(self.firstframe,text= "Variant
    1", variable=v, value="Variant 1")
    self.radiobutton.pack(side=TOP,anchor=W)
    self.radiobutton.select()
    self.radiobutton = Radiobutton(self.firstframe,text= "Variant
    2", variable=v, value="Variant 2")
    self.radiobutton.pack(side=TOP,anchor=W)
    self.radiobutton = Radiobutton(self.firstframe,text= "Variant
    3", variable=v, value="Variant 3")
    self.radiobutton.pack(side=TOP,anchor=W)



    self.secondframe = Frame(self.mainframe,bg="blue")
    self.secondframe.pack()
    self.var = Button(self.secondframe,text="What
    Variant",command=self.call)
    self.var.pack(expand=1,side=BOTTOM)



    def call(self):
    self.variant = v.get()
    print 'Input => "%s"' % self.variant

    class OneButton:
    def __init__(self):
    self.root = Tk()
    Button(self.root,text="click me",command=self.getvar).pack()
    def getvar(self):
    a=GetVariant()

    d = OneButton()
    d.root.mainloop()




    VK wrote:


    Hi!
    What I'm missing in following code? Cannot get the values of
    radiobuttons. Starting only one class (GetVariant), it works. When I put
    two classes together, it doesn't.
    Regards, VK
    from Tkinter import *
    class GetVariant:
    def __init__(self):
    self.root = Tk()
    self.mainframe = Frame(self.root,bg="yellow")
    self.mainframe.pack(fill=BOTH,expand=1)

    self.firstframe = Frame(self.mainframe,bg="red")
    self.firstframe.pack(side=BOTTOM,expand=1)

    global v
    v = StringVar()
    self.radiobutton = Radiobutton(self.firstframe,text= "Variant
    1", variable=v, value="Variant 1")
    self.radiobutton.pack(side=TOP,anchor=W)
    self.radiobutton.select()
    self.radiobutton = Radiobutton(self.firstframe,text= "Variant
    2", variable=v, value="Variant 2")
    self.radiobutton.pack(side=TOP,anchor=W)
    self.radiobutton = Radiobutton(self.firstframe,text= "Variant
    3", variable=v, value="Variant 3")
    self.radiobutton.pack(side=TOP,anchor=W)



    self.secondframe = Frame(self.mainframe,bg="blue")
    self.secondframe.pack()
    self.var = Button(self.secondframe,text="What
    Variant",command=self.call)
    self.var.pack(expand=1,side=BOTTOM)



    def call(self):
    self.variant = v.get()
    print 'Input => "%s"' % self.variant

    class OneButton:
    def __init__(self):
    self.root = Tk()
    Button(self.root,text="click
    me",command=self.getvar).pack()
    def getvar(self):
    a=GetVariant()

    d = OneButton()
    d.root.mainloop()
    Unfortunately, I can use only TkInter and Pmw
  • VK at May 28, 2005 at 9:22 pm

    Philippe C. Martin wrote:
    Hi,

    I think your second call to Tk() does it: this works although the look is
    different:


    from Tkinter import *
    class GetVariant:
    def __init__(self):
    self.root = Tk()
    self.mainframe = Frame(self.root,bg="yellow")
    self.mainframe.pack(fill=BOTH,expand=1)

    self.firstframe = Frame(self.mainframe,bg="red")
    self.firstframe.pack(side=BOTTOM,expand=1)

    global v
    v = StringVar()
    self.radiobutton = Radiobutton(self.firstframe,text= "Variant
    1", variable=v, value="Variant 1")
    self.radiobutton.pack(side=TOP,anchor=W)
    self.radiobutton.select()
    self.radiobutton = Radiobutton(self.firstframe,text= "Variant
    2", variable=v, value="Variant 2")
    self.radiobutton.pack(side=TOP,anchor=W)
    self.radiobutton = Radiobutton(self.firstframe,text= "Variant
    3", variable=v, value="Variant 3")
    self.radiobutton.pack(side=TOP,anchor=W)



    self.secondframe = Frame(self.mainframe,bg="blue")
    self.secondframe.pack()
    self.var = Button(self.secondframe,text="What
    Variant",command=self.call)
    self.var.pack(expand=1,side=BOTTOM)



    def call(self):
    self.variant = v.get()
    print 'Input => "%s"' % self.variant

    class OneButton:
    def __init__(self):
    self.root = Tk()
    Button(self.root,text="click me",command=self.getvar).pack()
    def getvar(self):
    a=GetVariant()

    d = OneButton()
    d.root.mainloop()




    VK wrote:

    Hi!
    What I'm missing in following code? Cannot get the values of
    radiobuttons. Starting only one class (GetVariant), it works. When I put
    two classes together, it doesn't.
    Regards, VK

    from Tkinter import *
    class GetVariant:
    def __init__(self):
    self.root = Tk()
    self.mainframe = Frame(self.root,bg="yellow")
    self.mainframe.pack(fill=BOTH,expand=1)

    self.firstframe = Frame(self.mainframe,bg="red")
    self.firstframe.pack(side=BOTTOM,expand=1)

    global v
    v = StringVar()
    self.radiobutton = Radiobutton(self.firstframe,text= "Variant
    1", variable=v, value="Variant 1")
    self.radiobutton.pack(side=TOP,anchor=W)
    self.radiobutton.select()
    self.radiobutton = Radiobutton(self.firstframe,text= "Variant
    2", variable=v, value="Variant 2")
    self.radiobutton.pack(side=TOP,anchor=W)
    self.radiobutton = Radiobutton(self.firstframe,text= "Variant
    3", variable=v, value="Variant 3")
    self.radiobutton.pack(side=TOP,anchor=W)



    self.secondframe = Frame(self.mainframe,bg="blue")
    self.secondframe.pack()
    self.var = Button(self.secondframe,text="What
    Variant",command=self.call)
    self.var.pack(expand=1,side=BOTTOM)



    def call(self):
    self.variant = v.get()
    print 'Input => "%s"' % self.variant

    class OneButton:
    def __init__(self):
    self.root = Tk()
    Button(self.root,text="click me",command=self.getvar).pack()
    def getvar(self):
    a=GetVariant()

    d = OneButton()
    d.root.mainloop()
    Sorry, but I don't get it. There is no deference between my code and
    your answer. I'm beginner...
  • Philippe C. Martin at May 28, 2005 at 9:26 pm
    PS: Since your starting with TKinter, and although I do not know what your
    goal is, I suggest you take a look at wxPython: it is _wonderfull_ ! (no
    offence to TCL/TK)

    Regards,

    Philippe






    VK wrote:
    Philippe C. Martin wrote:
    Hi,

    I think your second call to Tk() does it: this works although the look is
    different:


    from Tkinter import *
    class GetVariant:
    def __init__(self):
    self.root = Tk()
    self.mainframe = Frame(self.root,bg="yellow")
    self.mainframe.pack(fill=BOTH,expand=1)

    self.firstframe = Frame(self.mainframe,bg="red")
    self.firstframe.pack(side=BOTTOM,expand=1)

    global v
    v = StringVar()
    self.radiobutton = Radiobutton(self.firstframe,text= "Variant
    1", variable=v, value="Variant 1")
    self.radiobutton.pack(side=TOP,anchor=W)
    self.radiobutton.select()
    self.radiobutton = Radiobutton(self.firstframe,text= "Variant
    2", variable=v, value="Variant 2")
    self.radiobutton.pack(side=TOP,anchor=W)
    self.radiobutton = Radiobutton(self.firstframe,text= "Variant
    3", variable=v, value="Variant 3")
    self.radiobutton.pack(side=TOP,anchor=W)



    self.secondframe = Frame(self.mainframe,bg="blue")
    self.secondframe.pack()
    self.var = Button(self.secondframe,text="What
    Variant",command=self.call)
    self.var.pack(expand=1,side=BOTTOM)



    def call(self):
    self.variant = v.get()
    print 'Input => "%s"' % self.variant

    class OneButton:
    def __init__(self):
    self.root = Tk()
    Button(self.root,text="click me",command=self.getvar).pack()
    def getvar(self):
    a=GetVariant()

    d = OneButton()
    d.root.mainloop()




    VK wrote:

    Hi!
    What I'm missing in following code? Cannot get the values of
    radiobuttons. Starting only one class (GetVariant), it works. When I put
    two classes together, it doesn't.
    Regards, VK

    from Tkinter import *
    class GetVariant:
    def __init__(self):
    self.root = Tk()
    self.mainframe = Frame(self.root,bg="yellow")
    self.mainframe.pack(fill=BOTH,expand=1)

    self.firstframe = Frame(self.mainframe,bg="red")
    self.firstframe.pack(side=BOTTOM,expand=1)

    global v
    v = StringVar()
    self.radiobutton = Radiobutton(self.firstframe,text= "Variant
    1", variable=v, value="Variant 1")
    self.radiobutton.pack(side=TOP,anchor=W)
    self.radiobutton.select()
    self.radiobutton = Radiobutton(self.firstframe,text= "Variant
    2", variable=v, value="Variant 2")
    self.radiobutton.pack(side=TOP,anchor=W)
    self.radiobutton = Radiobutton(self.firstframe,text= "Variant
    3", variable=v, value="Variant 3")
    self.radiobutton.pack(side=TOP,anchor=W)



    self.secondframe = Frame(self.mainframe,bg="blue")
    self.secondframe.pack()
    self.var = Button(self.secondframe,text="What
    Variant",command=self.call)
    self.var.pack(expand=1,side=BOTTOM)



    def call(self):
    self.variant = v.get()
    print 'Input => "%s"' % self.variant

    class OneButton:
    def __init__(self):
    self.root = Tk()
    Button(self.root,text="click me",command=self.getvar).pack()
    def getvar(self):
    a=GetVariant()

    d = OneButton()
    d.root.mainloop()
    Sorry, but I don't get it. There is no deference between my code and
    your answer. I'm beginner...
  • VK at May 29, 2005 at 9:57 am

    Philippe C. Martin wrote:
    PS: Since your starting with TKinter, and although I do not know what your
    goal is, I suggest you take a look at wxPython: it is _wonderfull_ ! (no
    offence to TCL/TK)

    Regards,

    Philippe






    VK wrote:

    Philippe C. Martin wrote:
    Hi,

    I think your second call to Tk() does it: this works although the look is
    different:


    from Tkinter import *
    class GetVariant:
    def __init__(self):
    self.root = Tk()
    self.mainframe = Frame(self.root,bg="yellow")
    self.mainframe.pack(fill=BOTH,expand=1)

    self.firstframe = Frame(self.mainframe,bg="red")
    self.firstframe.pack(side=BOTTOM,expand=1)

    global v
    v = StringVar()
    self.radiobutton = Radiobutton(self.firstframe,text= "Variant
    1", variable=v, value="Variant 1")
    self.radiobutton.pack(side=TOP,anchor=W)
    self.radiobutton.select()
    self.radiobutton = Radiobutton(self.firstframe,text= "Variant
    2", variable=v, value="Variant 2")
    self.radiobutton.pack(side=TOP,anchor=W)
    self.radiobutton = Radiobutton(self.firstframe,text= "Variant
    3", variable=v, value="Variant 3")
    self.radiobutton.pack(side=TOP,anchor=W)



    self.secondframe = Frame(self.mainframe,bg="blue")
    self.secondframe.pack()
    self.var = Button(self.secondframe,text="What
    Variant",command=self.call)
    self.var.pack(expand=1,side=BOTTOM)



    def call(self):
    self.variant = v.get()
    print 'Input => "%s"' % self.variant

    class OneButton:
    def __init__(self):
    self.root = Tk()
    Button(self.root,text="click me",command=self.getvar).pack()
    def getvar(self):
    a=GetVariant()

    d = OneButton()
    d.root.mainloop()




    VK wrote:


    Hi!
    What I'm missing in following code? Cannot get the values of
    radiobuttons. Starting only one class (GetVariant), it works. When I put
    two classes together, it doesn't.
    Regards, VK
    from Tkinter import *
    class GetVariant:
    def __init__(self):
    self.root = Tk()
    self.mainframe = Frame(self.root,bg="yellow")
    self.mainframe.pack(fill=BOTH,expand=1)

    self.firstframe = Frame(self.mainframe,bg="red")
    self.firstframe.pack(side=BOTTOM,expand=1)

    global v
    v = StringVar()
    self.radiobutton = Radiobutton(self.firstframe,text= "Variant
    1", variable=v, value="Variant 1")
    self.radiobutton.pack(side=TOP,anchor=W)
    self.radiobutton.select()
    self.radiobutton = Radiobutton(self.firstframe,text= "Variant
    2", variable=v, value="Variant 2")
    self.radiobutton.pack(side=TOP,anchor=W)
    self.radiobutton = Radiobutton(self.firstframe,text= "Variant
    3", variable=v, value="Variant 3")
    self.radiobutton.pack(side=TOP,anchor=W)



    self.secondframe = Frame(self.mainframe,bg="blue")
    self.secondframe.pack()
    self.var = Button(self.secondframe,text="What
    Variant",command=self.call)
    self.var.pack(expand=1,side=BOTTOM)



    def call(self):
    self.variant = v.get()
    print 'Input => "%s"' % self.variant

    class OneButton:
    def __init__(self):
    self.root = Tk()
    Button(self.root,text="click me",command=self.getvar).pack()
    def getvar(self):
    a=GetVariant()

    d = OneButton()
    d.root.mainloop()
    Sorry, but I don't get it. There is no deference between my code and
    your answer. I'm beginner...
    Thanks for your help! Toplevel made the job.
    Reg. VK

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedMay 28, '05 at 8:04p
activeMay 29, '05 at 9:57a
posts9
users2
websitepython.org

2 users in discussion

VK: 5 posts Philippe C. Martin: 4 posts

People

Translate

site design / logo © 2023 Grokbase