[Tutor] CheckButtons reset to default values

Pooja Bhalode poojabhalode11 at gmail.com
Fri Feb 10 10:56:53 EST 2017


Hi Peter,

The code is as shown below.  I have put it in the manner you have told me.

root = Tk()
root.title("Design of Experiments with Parameter Estimation")
root.geometry("1000x1000")

def DesignPoint():
    print "Inside Design Point"
    rootdesign=Tk()
    rootdesign.title("Estimation of Experimental Precision for Data
Var-CoVar")
    rootdesign.geometry("600x400")
    frame1 = Frame(rootdesign)
    frame1.grid(row=0, column=0)

    ## Inserting Checkboxes:
    label1 = Label(frame1, text="1. Design Point Suggestions")
    label1.grid(row=0, column=0,sticky=W )
    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)

    label3 = Label(frame1, text="3. Simulation of proposed Experiments: ")
    label3.grid(row=5, column=0,sticky=W)

    label4 = Label(frame1, text="4. Calculate sensitivities")
    label4.grid(row=6, column=0,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)

    rootdesign.mainloop()


## Secondary menu bar:
menusec = Frame(root, bg="white")
butt1 = Button(menusec, text="Part One", command=DesignPoint)
butt1.pack(side=LEFT, padx=1)
menusec.pack(side=TOP, fill=X)


root.mainloop()

It still doesn't work for me for the reason I am not able to figure out.
Please let me know.
Thank you once again in advance.

Pooja

On Fri, Feb 10, 2017 at 4:48 AM, Peter Otten <__peter__ at web.de> wrote:

> 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.
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>


More information about the Tutor mailing list