【发布时间】:2015-06-11 18:44:15
【问题描述】:
我正在使用 Tkinter 在 Python 2.7 中创建一个 GUI,现在我正在尝试使用 validatecommand 对我的输入框进行值检查。当我运行 GUI 时,它会运行检查功能,因为它是“强制的”,但我也希望它在我操作 GUI 中的输入框值时调用检查功能。有很多代码行,所以我只包含(我认为)与 validatecommand 调用相关的代码。让我知道是否缺少任何信息。
任何人都知道为什么在输入框定义中调用 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()
【问题讨论】:
标签: python python-2.7 user-interface tkinter