Python知識(shí)分享網(wǎng) - 專業(yè)的Python學(xué)習(xí)網(wǎng)站 學(xué)Python,上Python222
learning tkinter PDF 下載
發(fā)布于:2024-08-13 11:19:46
(假如點(diǎn)擊沒反應(yīng),多刷新兩次就OK!)

learning tkinter PDF 下載 圖1

 

 

資料內(nèi)容:

Adding validation to an Entry widget
To restrict the characters that can be typed into an entry widget, only numbers for instance, a
validate command can be added to the entry. A validate command is a function that return True if
the change is accepted, False otherwise. This function will be called each time the content of the
entry is modified. Various arguments can be passed to this function, like the type of change
(insertion, deletion), the inserted text, ...
def only_numbers(char):
return char.isdigit()
validation = parent.register(only_numbers)
entry = Entry(parent, validate="key", validatecommand=(validation, '%S'))
The validate option determines the type of event that triggers the validation, here, it's any
keystroke in the entry. The '%S' in the validatecommand option means that the inserted or deleted
character is passed in argument to the only_numbers function. The full list of possibilities can be
found here.
Getting int From Entry Widget
When using the .get() method whatever is in the entry widget will be converted into a string. For
example, regardless of the type of input(It can be a number or sentence), the resulting outcome
will be a string. If the user types 4 the o