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?