Code: Alles auswählen
# -*- coding: utf-8 -*-
try:
import tkinter as tk
except ImportError:
import Tkinter as tk
from functools import partial
class Application(tk.Tk):
def __init__(self,**kwargs):
tk.Tk.__init__(self,**kwargs)
# widget definitions ===================================
self.entry = tk.Entry(self,name='#0_entry',validate='key')
self.entry.pack()
self.entry.insert(0,1)
self.entry['validatecommand'] = partial(self.validate,self.entry)
def validate(self,entry):
correct = False
print(self.entry.get())
try:
float(self.entry.get())
correct = True
except:
pass
return correct
if __name__ == '__main__':
Application().mainloop()