Prevent GUI layout from changing?

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Sun Apr 6 16:15:49 EDT 2008


En Sun, 06 Apr 2008 15:12:55 -0300, <skanemupp at yahoo.se> escribió:

I can't help with your sizing problem, I don't know grids. But don't do  
this:

>     def Display(self, number):
>         self.expr = self.expr + number
>         self.lbText = Label(self, text=self.expr)
>         self.lbText.grid(row=0, column=0)
>
>     def Calculate(self):
>         self.expr = str(eval(self.expr))#try catch tex 3+6+
>         self.lbText = Label(self, text=self.expr)
>         self.lbText.grid(row=1, column=1)
>         self.expr = ""

You're creating a *new* Label object for each keystroke (they stack on the  
same place and only the newest is visible, I presume).
Instead, you should change the text inside the existing widget:

     self.lbText.config(text=self.expr)

(there is no need to reposition the widget)
Label is described here http://effbot.org/tkinterbook/label.htm
and you may want to learn to use Tkinter variables:  
http://effbot.org/tkinterbook/variable.htm

-- 
Gabriel Genellina




More information about the Python-list mailing list