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() 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()
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()
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...
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...
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()
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()
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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
by: JeffFinnan |
last post by:
<form name=form1>
Load in Viewer Window:
<input name="radiobutton" type="radio" value="1" checked onClick="1">
1
<input type="radio" name="radiobutton" value="2" onClick="2">...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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...
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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...
| |