0
import Tkinter
import tkMessageBox

class Values(Tkinter.Tk):
    """docstring for Values"""
    def __init__(self, parent):
        Tkinter.Tk.__init__(self,parent)
        self.parent = parent
        self.initialize()

    def initialize(self):
        self.grid()

        self.Val1Lbl = Tkinter.Label(self,text="Value 1")
        self.Val1Lbl.grid(row=0,column=0)

        self.Val1Txt = Tkinter.Entry(self)
        self.Val1Txt.grid(row=0,column=1)
        self.err_l1 = Tkinter.Label(self, text='', fg='red')
        self.err_l1.grid(row=0,column=2)

        self.val1 = None
        self.val2 = None

        SubmitBtn = Tkinter.Button(self, text="Submit",command=self.hide_label)
        SubmitBtn.grid(row=1,column=2)


    def hide_label(self, event=None):
            self.val1=self.Val1Txt.get()
            if self.val1.strip() == '':
               self.err_l1[''] = 'error'

i want the error message to be displayed beside the text box,how can i trigger the label after clicking the submit button i am new to python so can anyone help me..!

user9213
  • 309
  • 1
  • 2
  • 11
  • Try putting a label that is normally "Not Visible" next to the TextBox. Then change its properties when the error is triggered. – rch Jul 18 '14 at 11:07
  • i'm very new to python can you please tell me how to place a hidden label and then trigger it – user9213 Jul 18 '14 at 11:09
  • Look a this [Post]:(http://stackoverflow.com/questions/3819354/in-tkinter-is-there-any-way-to-make-a-widget-not-visible) – rch Jul 18 '14 at 11:16

1 Answers1

0

You can use a label defined as follows ..

Label(root, text = err_msg, fg='red').place(x = entry.x + entry.width + 10, y = entry.y)

Even better, you can place the label first, hidden (or just with no text), then display the message in red using it ..

err_l1 = Label(root, text='', fg='red') # the empty text is there only so that we can do err_l1['text'] = err_msg

# now in the submit button click event handler ..

if entry.get().strip() == '':
    err_l1['text'] = err_msg # as simple as that ;)
Amr Ayman
  • 1,129
  • 1
  • 8
  • 24