0
我使用Tkinter在Python 2.7中创建了一个GUI,现在正在尝试使用validatecommand为我的输入框实现值检查。当我运行GUI时,它运行检查函数,因为它是'强制'的,但我也希望它在GUI中处理输入框值时调用检查函数。有很多代码行,所以我只包含了代码(我认为)与validatecommand调用相关。如果有任何信息丢失,请告知我。无法在python 2.7中调用validatecommand Tkinter GUI
任何人都可以看到为什么在输入框定义中的validatecommand调用没有任何反应吗?我对编程相当陌生,所以任何见解都值得赞赏。谢谢!
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()