Zahlen nur zulassen und "."-Eingabe in Einträge [Duplikat]Python

Python-Programme
Anonymous
 Zahlen nur zulassen und "."-Eingabe in Einträge [Duplikat]

Post by Anonymous »

Ich möchte nur Zahlen von 0-9 und ein "" eingeben. Wenn ich eine Float -Nummer eingeben möchte. Bisher habe ich das: < /p>

Code: Select all

def keylistener(event):
ACCEPTED = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "."]
if not event.char in ACCEPTED:
pass
# Dont let the character be inputed
#....

tk.bind('', keylistener)
< /code>
Kann mir jemand helfen?from tkinter import *

tk = Tk()
tk.title("Only Numbers")
tk.configure(bg="black")
tk_frame = Frame(relief=RAISED,bd=8,bg="gray")
category = StringVar(tk_frame)

def keylistener(event):
ACCEPTED = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "."]
if event.char not in ACCEPTED:
return "break"
# Dont let the character be inputed

entry = Entry(tk_frame,bg="white",fg="black")

tk_frame.grid()
entry.grid(column=1, row=1)

# Start Keylistener
tk.bind('', keylistener)

tk.mainloop()

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post