[Tutor] CheckButtons reset to default values
Peter Otten
__peter__ at web.de
Fri Feb 10 04:48:31 EST 2017
Pooja Bhalode wrote:
> Hi,
>
> I have a bunch of checkbuttons in my code and a default settings button
> which restores the original setting in the checkbuttons. The code is given
> below:
>
>
> var1 = IntVar()
> var2 = IntVar()
> var3 = IntVar()
> var4 = IntVar()
> Checkbutton(frame1, text = "Vertices", variable=var1, onvalue=1,
> offvalue=0).grid(row=1, column = 1, sticky=W)
> Checkbutton(frame1, text = "Edges", variable=var2).grid(row=2, column
> =
> 1, sticky=W)
> Checkbutton(frame1, text = "Faces", variable=var3).grid(row=3, column
> =
> 1, sticky=W)
> check = Checkbutton(frame1, text = "Center", variable=var4)
> check.grid(row=4, column = 1, sticky=W)
> check.select()
>
> label2 = Label(frame1, text="2. Cut off Improvement %")
> label2.grid(row=5, column=0,sticky=W)
> Entry2 = Entry(frame1)
> Entry2.insert(END, '05')
> Entry2.grid(row=5, column = 1, sticky = W)
>
> def default():
> print "Inside default"
>
> var1.set(0)
> var2.set(0)
> var3.set(0)
> var4.set(1)
> Entry2.delete(0, END)
> Entry2.insert(END,'05')
>
> Button(frame1, text = "Select Default value",
> command=default).grid(row=0, column = 2, sticky=W)
>
>
> This resets the Entry2 but it does not reset the checkbuttons selection to
> the values specified in default function.
> Can some one please tell me where I am going wrong?
The problem has to be elsewhere in your code. If I run a script
from Tkinter import *
root = frame1 = Tk()
if 1:
# your snippet shown above goes here
root.mainloop()
clicking the button unchecks Vertices, Edges, Faces and checks Center.
More information about the Tutor
mailing list