Good evening all.

 

I am writing a program using python 2.4, glade 2 and pygtk.  It takes input from the user using textentry boxes.  The input should be a number.  When the user keys the data in, it automatically left justifies.  The function below, takes the input for four boxes and right justifies it by using an ugly, string format.  The boxes are 45 characters big, so I use the len function to fit them into the box.  The code is below.

 

I am looking for a way to set the text entry up, so that there is a decimal point in the box regardless of what the user does and I am also looking for a way to keep the numbers right justified.

 

Any suggestions or comments as always are greatly appreciated.

 

Regards,

 

John.

 

 

def callback36(self,data,text37,text38,text39,text40,text41,text42,label):

        a = text37.get_text()

       

        b = text38.get_text()

        c = text39.get_text()

        d = text40.get_text()

        a= float(a)

        b= float(b)

        c= float(c)

        d= float(d)

       

        try:

           

            e = float(a + b + c + d)

            g = e/a

            e = "%0.2f" % e

           

            g = "%0.2f" % g

            g = str(g)

            label.hide()

            e = "                                         %s" % e

            a = "                                         %s" % a

            b = "                                         %s" % b

            c = "                                         %s" % c

            d = "                                         %s" % d

            g = "%s%%" % g

            text42.set_text(str(g))

            if len(e)>45:

                x = len(e) - 45

                x = x + 4

                y = e[x:]

                text41.set_text(str(y))              

                return

            else:

                text41.set_text(str(e))

                return

      

        except:

            label.show()

            return

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to