lundi 7 mars 2016

enabling entry box based on check box condition in python 2.7 without classes

I want an entry box to be enabled when check box is checked without using classes in python 2.7 .I have this so far but it doesn't work and I don't know where I am going wrong. New to this language so all I can guess is that I am probably calling function in the wrong way.

import os
import Tkinter as tk
from Tkinter import *
from ttk import *

def text_func(decimation_value):

            if decimation == 1:
                factorText1.configure(state='disabled')
                decimation = 0
            else:
                factorText1.configure(state='normal')
                decimation = 1
root = tk.Tk()
root.title("LIGO")

note = Notebook(root, width=1365, height=1000)
GUI_tab = tk.Frame(note,width=25,height=250, background="SNOW")
plot_tab = tk.Frame(note, background="SNOW")
quit_tab = tk.Frame(note, background="SNOW")

note.add(GUI_tab, text="GUI")
note.add(plot_tab, text="PLOT")
note.add(quit_tab, text="QUIT")

note.grid()
note.enable_traversal()

#------------------------------   GUI-TAB   --------------------------------
frame1 = tk.Frame(GUI_tab, background="SNOW")
frame1.pack(fill="both")

labelframe4 = tk.LabelFrame(frame1, text="Other Options", foreground="purple")
labelframe4.pack(fill="both", expand="yes")
labelframe4.configure(background="SNOW")

decimation=tk.IntVar(value=0)
decimation_check=tk.Checkbutton(labelframe4, text="Decimation   ", variable=decimation, background="SNOW",
                                   command=text_func(decimation))
decimation_check.grid(row=0, column=2, sticky="W", padx=10, pady=5)

factor_label1=tk.Label(labelframe4, text="Factor:", background="SNOW")
factor_label1.grid(row=1, column=2, sticky="W", padx=10, pady=5)
factorText1=tk.IntVar()
factor_entry1=tk.Entry(labelframe4, text="Factor", textvariable=factorText1, width=6, background="SNOW", state=DISABLED)
factor_entry1.grid(row=1, column=2, sticky="E", pady=5, ipadx=10)

root.configure(bg="snow")
root.state('zoomed')
root.resizable(0,0)
root.mainloop()




Aucun commentaire:

Enregistrer un commentaire