473,396 Members | 1,935 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Getting value of radiobutton trouble

VK
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()
Jul 19 '05 #1
8 2822
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()


Jul 19 '05 #2
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()


Jul 19 '05 #3
VK
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...
Jul 19 '05 #4
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...


Jul 19 '05 #5
VK
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()


Jul 19 '05 #6
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()



Jul 19 '05 #7
VK
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
Jul 19 '05 #8
VK
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
Jul 19 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: bbxrider | last post by:
i have 2 radio buttons 1 for yes and 1 for no, it is mandatory for one to be checked, and am purposely leaving both blank on the page when i tested for .value, when neither was checked, an alert...
2
by: JeffFinnan | last post by:
<form name=form1> Load in Viewer Window: <input name="radiobutton" type="radio" value="1" checked onClick="1"> 1&nbsp;&nbsp;&nbsp; <input type="radio" name="radiobutton" value="2" onClick="2">...
1
by: R.G. Vervoort | last post by:
I would like to make a script wich makes a select visible or not visible depending on what radio button is selected. If the radiobutton with the value "nieuw" is selected the pulldown is not...
1
by: MickG | last post by:
I am trying to change the value of the variable "hard" according to which radio button is pressed and I am having no joy. Could anyone help me with this, the problematic section is marked with...
4
by: darrel | last post by:
I have a contact form that a person submits to the server. In ASP, you'd make a page, post the form to another page, which would grab the values and do somethign with them. in ASP.NET, it...
2
by: Rob | last post by:
Hi all, I've got multiple sets of radio button that are dynamically created in code and populated by a database query. The query returns about 20 recordsets with 3 radio buttons per recordset and...
2
by: Rich | last post by:
Hello, Is it possible to assign a value to a groupbox by selecting a radiobutton contained in the groupbox? Say you assign a value of 1 to radbtn1, 2 for radbtn2, 3 for radbtn3 all contained...
0
by: Nathan Sokalski | last post by:
In the RadioButton and CheckBox controls, there is no Value attribute. The html <inputtag has a value attribute, which is used by both type="radio" and type="checkbox". The RadioButtonList and...
12
by: ive1122 | last post by:
Hi guys, I am looking into create a dynamic survey as posted in Get User Input From Dynamic Controls but with some different environment Below is what i am trying to do: First when the user...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.