1.import library
โค้ด: เลือกทั้งหมด
from tkinter import *
โค้ด: เลือกทั้งหมด
def MoneyValidation(S):
if S.isdigit():
return True
root.bell()
return False
โค้ด: เลือกทั้งหมด
root = Tk()
root.geometry('200x200')
root.title("Test")
vcmd = (root.register(MoneyValidation), '%S')
E = Entry(root, bg='gray', validate='key', vcmd=vcmd)
E.pack()
root.mainloop()
โค้ด: เลือกทั้งหมด
def MoneyValidation(S):
if S.isalpha():
return True
root.bell()
return False
เป็นอย่างไรบ้างครับหวังว่าคงจะพอมีประโยชน์สำหรับคนที่กำลังทำโปรเจคอยู่นะครับ ซึ่งเราสามารถนำไปกำหนดเป็นเงื่อนไขต่างๆที่เราต้องการกำหนดให้กรอกได้แค่ตัวเลขเช่น อายุ หรือเลขบัตรประชาชนได้
อ้างอิง
https://sites.google.com/site/porkaermlgc/fangkchan-ni-phasa-c/fangkchan-keiyw-kab-taw-xaksr-character-functions
https://stackoverflow.com/questions/8959815/restricting-the-value-in-tkinter-entry-widget
https://www.reddit.com/r/learnpython/comments/985umy/limit_user_input_to_only_int_with_tkinter/
ศึกษาเพิ่มเติม
บทความแชร์ความรู้เกี่ยวกับ Python
วีดีโอสอนบทเรียน python
เทคนิคการเขียน python
Python GUI (Tkinter) : การ Browse file แบบ multiple file จากการกดปุ่ม Button