0

I have a problem with this part of my program. I have to write data into Tk.Entry, but if I write letter(a,z,R,K....),it crash. I can´t use STRING, because i need input as INT(or FLOAT), because I need input for further calculation. How can I check that input in TK.Entry doesn´t contain letters, but only numbers (1...9,0) (or point (.)). Thank you.

P.S: Please don´t evaluate my code, I know that it´s terrible :-)

import Tkinter as Tk
main=Tk.Tk()
main.minsize(440,330)
hl=Tk.Frame(main)
hl.pack()
def lichobobsvyp(*par):
    main.title('Obsah lichoběžníku - Výpočet')
    Tk.Label(hl, text ='Obsah lichoběžníku - Výpočet', font ='Arial 15').pack()
    rlichobobsa = Tk.LabelFrame(hl, text ='Strany A')
    rlichobobsa.pack()
    hlichobobsa = Tk.Entry(rlichobobsa, textvariable =thlichobobsa)
    hlichobobsa.pack()
    Tk.Button(hl, text ='Ok', command = lambda: destroy(lichobobsvysl)).pack()
def lichobobsvysl(*par):
    dlichobobsa = float(thlichobobsa.get())
def destroy(x,*par):
    for wid in hl.winfo_children():
        wid.destroy()
    x()
    return
thlichobobsa=Tk.DoubleVar()
lichobobsvyp()
main.mainloop()   
John
  • 43
  • 1
  • 7
  • please read and follow the instructions here: [How to create a Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve) – Bryan Oakley Aug 24 '17 at 12:24
  • 1
    Possible duplicate of [Interactively validating Entry widget content in tkinter](https://stackoverflow.com/questions/4140437/interactively-validating-entry-widget-content-in-tkinter) – Mike - SMT Aug 24 '17 at 13:03
  • Just a note: Your `lichbobsvysl` does nothing for your program. also I don' think you can use destroy the way you are trying to. You need to use destroy on a variable or object like `var_name.destroy()`. Currently you are trying to destroy a function but that wont work anyway. – Mike - SMT Aug 24 '17 at 13:12

0 Answers0