我想添加功能用户不允许输入0作为条目字段中的第一个数字
我想添加功能用户不允许输入0作为条目字段中的第一个数字,请帮助我解决问题。
vcmd = (root.register(self.enter_only_digits), '%P', '%d')
self.text_num = tk.Entry(validate='key', validatecommand=vcmd)
self.text_num.place(x=100, y=210, width=100, height=20)
def enter_only_digits(self, entry, action_type) -> bool:
if action_type == '1' and not entry.isdigit():
return False
return True
I want to add functionality User is not allowed to enter 0 as the first number in the Entry field, please help me to solve the problem.
vcmd = (root.register(self.enter_only_digits), '%P', '%d')
self.text_num = tk.Entry(validate='key', validatecommand=vcmd)
self.text_num.place(x=100, y=210, width=100, height=20)
def enter_only_digits(self, entry, action_type) -> bool:
if action_type == '1' and not entry.isdigit():
return False
return True
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于该条目是字符串,如果启动索引包含0 as:
since the entry is a string it can be checked if starting index contains 0 as: