lundi 7 mai 2018

How to disable an entry depending on a checkbox using tkinter?

I'm using tkinter in Python to create a GUI. I want the user to be able to give a maximum and minimum value and if it is a constant value to only enter that value. I would like this by implementing a checkbox which they can tick and then the maximum value box is greyed out. Underneath is my code

from tkinter import *

class GUI(object):
    def __init__(self, master):
        self.master = master
        master.title("Variabelen")
        Label(master, text="Min").grid(row=0, column=1)
        Label(master, text="Max").grid(row=0, column=2)
        Label(master, text="Vaste waarde").grid(row=0, column=3)

        Label(master, text="Oppervlakte chiller").grid(row=1)
        Label(master, text="Diameter buizen").grid(row=2)

        aChillerMin = Entry(master)
        aChillerMax = Entry(master)
        dMin = Entry(master)
        dMax = Entry(master)

        aChillerMin.grid(row=1, column=1)
        aChillerMax.grid(row=1, column=2)
        aChillerVast = IntVar()
        chk = Checkbutton(root, variable=aChillerVast).grid(row = 1, column = 3)

        if aChillerVast.get():
           aChillerMax.config(state=DISABLED)

        dMin.grid(row=2, column=1)
        dMax.grid(row=2, column=2)

root = Tk()
myGUI = GUI(root)
root.mainloop()




Aucun commentaire:

Enregistrer un commentaire