[Tutor] Setting & validating dialog box entries

perl lover hemanexp@yahoo.com
Sun May 4 03:22:01 2003


hi,
   i am using tkSimpleDialog box to display employee
name and number. I want my entry box should contain
some intial values set in "body" routine while loading
the dialog box. Which fuction is used to set a value
for entry widget? Moreover how can i ensure my entry
widget contains proper values? That means name box
should not allow numbers and salary box should not
contain string. As soon as i type an invalid character
( a number in name box) i expect an message box to be
poped out stating the error instead of displaying the
messagebox after pressing "Ok". How can i get a
messagebox as soon as the condition is violated? 
 
   My program is given below.

from Tkinter import *
import tkMessageBox
import tkSimpleDialog
import string
root = Tk()
Button(root, width=10, height=10).pack()

class MyDialog(tkSimpleDialog.Dialog):

    def body(self, master):

        Label(master, text="First:").grid(row=0)
        Label(master, text="Second:").grid(row=1)

        self.empname = Entry(master)
        self.eno = Entry(master)

        self.empname.grid(row=0, column=1)
        self.eno.grid(row=1, column=1)
	
	# Here i want to set values for entry widgets
	#self.empname.configure(textvariable = "suresh")


    def validate(self):
        try:
            name= string(self.empname.get())
            eno = string.atoi(self.en.get())
            self.result = name, eno
            return 1
        except ValueError:
            tkMessageBox.showwarning("Bad input",
"Illegal values, please try again")
            return 0

    def apply(self):

        name = string.atoi(self.empname.get())
        eno = string.atoi(self.eno.get())
        print name, eno # or something

MyDialog(root)
root.mainloop()


__________________________________
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.
http://search.yahoo.com