jeudi 28 juillet 2016

python 3.5 checkbox value not correct

I wrote a code in python 3.5 with tkinter and I'm having problems with getting the correct values from the current state (True/False) of the checkboxes. from some reason I don't always the correct value. This is my code: top = tk.Tk()

# build interface using 4 inputframes
inputFrame_video_rate = tk.Frame(top)
inputFrame_video_rate.pack()
inputFrame_video_rate.place(bordermode=tk.OUTSIDE, height=20, width=200, x=90, y=70)

inputFrame_video_output = tk.Frame(top)
inputFrame_video_output.pack()
inputFrame_video_output.place(bordermode=tk.OUTSIDE, height=20, width=400, x=90, y=100)

inputFrame_processing_info = tk.Frame(top)
inputFrame_processing_info.pack()
inputFrame_processing_info.place(bordermode=tk.OUTSIDE, height=20, width=400, x=90, y=130)

top.wm_title("Enter parameter details")
top.geometry("650x550")
label_video_rate = tk.Label(inputFrame_video_rate, text="video rate: ")
label_video_rate.pack(side=tk.LEFT)
entyr_video_rate = tk.Entry(inputFrame_video_rate, bd=2, width=50)
entyr_video_rate.insert(0, '10')
entyr_video_rate.pack(side=tk.LEFT)

label_video_output = tk.Label(inputFrame_video_output, text="output video file name:")
label_video_output.pack(side=tk.LEFT)
entry_video_output = tk.Entry(inputFrame_video_output, bd=2, width=50)
entry_video_output.pack(side=tk.LEFT)

label_video_output = tk.Label(inputFrame_video_output, text="")
label_video_output.pack(side=tk.LEFT)

# instruction
instructionsCheckBox = "Choose which skeleton to create (you can choose both)"
instructionsLabel = tk.Label(top, text=instructionsCheckBox, width=500, font=("Helvetica", 9))
instructionsLabel.pack()
instructionsLabel.place(x=15, y=130, width=400)


var_whole_body = tk.IntVar()
var_no_legs= tk.IntVar()
checkbox_whole_body = tk.Checkbutton(top, text = "Whole Body", variable = var_whole_body, \
                 onvalue = True, offvalue = False, height=5, \
                 width = 200)

show_skeleton_whole_body = var_whole_body.get()
print ('main before select: show_skeleton_whole_body')
print (show_skeleton_whole_body)

checkbox_whole_body.select()

show_skeleton_whole_body = var_whole_body.get()
print ('main after select: show_skeleton_whole_body')
print (show_skeleton_whole_body)


checkbox_no_legs = tk.Checkbutton(top, text = "  No Legs", variable = var_no_legs, \
                 onvalue = True, offvalue = False, height=4, \
                 width = 200)

show_skeleton_no_legs = var_no_legs.get()
print ('main before select: show_skeleton_no_legs')
print (show_skeleton_no_legs)

checkbox_no_legs.select()

show_skeleton_no_legs = var_no_legs.get()
print ('main after select: show_skeleton_no_legs')
print (show_skeleton_no_legs)

checkbox_whole_body.pack(side=tk.LEFT)
checkbox_whole_body.place(x=15, y=200, width=100)
checkbox_no_legs.pack(side=tk.LEFT)
checkbox_no_legs.place(x=15, y=250, width=100)

and this is the output I get from the prints:

main before select: show_skeleton_whole_body 0 main after select: show_skeleton_whole_body 0 main before select: show_skeleton_no_legs 0 main after select: show_skeleton_no_legs 0

for some reason the select() command didn't change the value from 0 to 1.

anybody knows what the problem is?

Thanks David




Aucun commentaire:

Enregistrer un commentaire