[Tutor] CheckButtons reset to default values
Alan Gauld
alan.gauld at yahoo.co.uk
Fri Feb 10 13:01:50 EST 2017
On 10/02/17 15:56, Pooja Bhalode wrote:
> root = Tk()
> root.title("Design of Experiments with Parameter Estimation")
> root.geometry("1000x1000")
>
> def DesignPoint():
> rootdesign=Tk()
You should o0nly have one root. This create a new root
everytime you xcall Designpoint and even if thats only
once you still have a root already at the global level.
It would be better to define the function to have
a root parameter that you can pass in when you call it.
> rootdesign.title("Estimation of Experimental Precision for Data
> Var-CoVar")
> rootdesign.geometry("600x400")
Are you trying to create a second window? If so you
should probably use the TopLevel widget for that but
with the same toplevel root.
Alternatively you could create a Dialog using the Dialog
module but that probably requires a bit more OOP than
you seem comfortable with.
> 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()
These vars should probably be declared and initialised
outside the function.
> 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)
>
The above is ok but...
> 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')
You have now defined this function inside the Designpoint
function. It should probably be outside except you would
lose visibility of the vars - which is why they should be global.
> Button(frame1, text = "Select Default value",
> command=default.grid(row=0, column = 2, sticky=W)
But you cannot apply grid to a function. your command
should be default. In suspect you are just missing a
closing parenthesis
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.
You have quite a few issues. The main things you should sort out are:
1) only use one root.
2) put the vars and default definitions outside the
designpoint function.
3) add the closing parenthesis.
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos
More information about the Tutor
mailing list