Apex14
Apex14

Reputation: 15

Unable to call validatecommand in python 2.7 Tkinter GUI

I am creating a GUI in Python 2.7 using Tkinter and am now trying to implement a value check for my entry boxes using validatecommand. When I run the GUI, it runs the check function because it is 'forced' but I also want it to call the check function when I manipulate the entry box values in the GUI. There are very many lines of code so I have only included the code that (I think) is relevant for the validatecommand call. Let me know if any information is missing.

Can anyone see why nothing happens with the validatecommand call in the Entry box definition? I am fairly new to programming so any insight is appreciated. Thanks!

import Tkinter as tk

class GUI:
    def __init__(self, master):
        self.master = master
        self.create_content()

    def create_content(self):
        self.create_frameSP()

    def create_frameSP(self): 
        vcmd = (self.master.register(self.val_check), '%d', '%i', '%P', '%s', '%S', '%v', '%V', '%W')
        self.entry_frameSP6 = tk.Entry(self.sframe2_frameSP, textvariable = self.varNPU, validate = 'all', validatecommand = vcmd, justify = tk.CENTER, width = 8)

    def val_check(self, d, i, P, s, S, v, V, W):
        print("d='%s'" % d)
        print("i='%s'" % i)
        print("P='%s'" % P)
        print("s='%s'" % s)
        print("S='%s'" % S)
        print("v='%s'" % v)
        print("V='%s'" % V)
        print("W='%s'" % W)

def main():
    root = tk.Tk()
    GUI(root)
    root.mainloop()

Upvotes: 0

Views: 61

Answers (1)

Bryan Oakley
Bryan Oakley

Reputation: 385970

val_check must return True or False.

Upvotes: 3

Related Questions