0
def create_widgets(self):

        B_PAD = 4
        PAD_X = 3; PAD_Y = 2
        NUM_PAD = 7

        '''Create Boolean variables for all the buttons.'''
        def create_button_vars():
            self.backspace = BooleanVar()
            self.CE = BooleanVar()
            self.C = BooleanVar()
            self.MC = BooleanVar()
            self.MR = BooleanVar()
            self.Mminus = BooleanVar()
            self.num = []
            for i in range (10):
                self.num.append(BooleanVar())
            self.plusMinus = BooleanVar()
            self.period = BooleanVar()
            self.divide = BooleanVar()
            self.multiply = BooleanVar()
            self.subtract = BooleanVar()
            self.add = BooleanVar()
            self.sqrt = BooleanVar()
            self.percent = BooleanVar()
            self.recip = BooleanVar()
            self.equals = BooleanVar()
                     
        #create_widgets() starts here.
        #Calculator display.
        self.display = Text(self, width = 25, height = 1, wrap = NONE)
        self.display.grid(row = 1, column = 1, columnspan = 5, sticky = W)

        #Memory stored indicator.
        self.memDisplay = Text(self, width = 2, height = 1, wrap = NONE)
        self.memDisplay.grid(row = 2, column = 0, sticky = W)

        create_button_vars()

        #First row.
        Button(text = 'Backspace', command = self.backspace).grid\
                    (row = 2, column = 1, columnspan = 2,\
                     padx = PAD_X, pady = PAD_Y, sticky = N)
        Button(text = 'CE', command = self.CE).grid\
                    (row = 2, column = 3, columnspan = 1, ipadx = 21,\
                     padx = PAD_X, pady = PAD_Y, sticky = N)
        Button(text = 'C', command = self.C).grid\
                    (row = 2, column = 4, columnspan = 2, ipadx = 24,\
                     padx = PAD_X, pady = PAD_Y, sticky = N)

        #Second row.
        Button(text = 'MC', command = self.MC).grid\
                    (row = 3, column = 0, sticky = N)
        Button(text = '7', command = self.num[7]).grid\
                    (row = 3, column = 1, ipadx = NUM_PAD, padx = B_PAD,\
                     sticky = N)
        Button(text = '8', command = self.num[8]).grid\
                    (row = 3, column = 2, ipadx = NUM_PAD, padx = B_PAD,\
                     sticky = N)
        Button(text = '9', command = self.num[9]).grid\
                    (row = 3, column = 3, ipadx = NUM_PAD, padx = B_PAD,\
                     sticky = N)
        Button(text = '/', command = self.divide).grid\
                    (row = 3, column = 4, ipadx = NUM_PAD, padx = B_PAD,\
                     sticky = N)

Hello everyone, I am learning how to code GUIs in 2.5.1. My current task is to attempt to program a four-function calculator. So far, I have the above for my create_widgets() method.

Obviously that's not a full calculator, which I don't want to get to until I can resolve the following problem--the GUI looks like this:

[img]http://img64.imageshack.us/img64/9138/calculatorgoofiness.jpg[/img]

I've tried all sorts of combinations with the column span and numbering, but no matter what I do, the upper text line always ends at a horizontal position before the CE, C, 7, 8, 9, etc. keys do. What am I doing wrong?

2
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by vegaseat
0

Someone on another forum said that I " forgot to pass self as master to the Buttons." What exactly does that mean?

0

By default the buttons will appear on the root window. If you want them somewhere else, you have to specify the new master.

Edited by vegaseat: n/a

0

I fixed it. I was forgetting to start off the Button declarations with Button(self, ...).

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.