Tkinter: making buttons the same size?

S

skanemupp

on windows vista these buttons dont have the same size, the "/"
shrinks a little. how do i make them the same size or prevent
shrinking?
a mac-user told me they look the same to him so maybe it doesnt shrink
on macs but it does when using VISTA.

i tried some .propagate and extend-stuff but didnt work.

#! /usr/bin/env python
from Tkinter import *
import tkMessageBox

class GUIFramework(Frame):
"""This is the GUI"""

def __init__(self, master=None):
"""Initialize yourself"""

"""Initialise the base class"""
Frame.__init__(self,master)

"""Set the Window Title"""
self.master.title("Calculator")

"""Display the main window"
with a little bit of padding"""
self.grid(padx=10,pady=10)
self.CreateWidgets()



def CreateWidgets(self):


self.btnDisplay = Button(self,text='1',command=lambda
n=1:self.Display(n))
self.btnDisplay.grid(row=3, column=0, padx=5, pady=5)

self.btnDisplay = Button(self,text='/',command=lambda
n="/":self.Display(n))
self.btnDisplay.grid(row=6, column=3, padx=5, pady=5)

def Display(self, number):
print number

if __name__ == "__main__":
guiFrame = GUIFramework()
guiFrame.mainloop()
 
G

Guilherme Polo

2008/4/5 said:
on windows vista these buttons dont have the same size, the "/"
shrinks a little. how do i make them the same size or prevent
shrinking?
a mac-user told me they look the same to him so maybe it doesnt shrink
on macs but it does when using VISTA.

i tried some .propagate and extend-stuff but didnt work.

#! /usr/bin/env python
from Tkinter import *
import tkMessageBox

class GUIFramework(Frame):
"""This is the GUI"""

def __init__(self, master=None):
"""Initialize yourself"""

"""Initialise the base class"""
Frame.__init__(self,master)

"""Set the Window Title"""
self.master.title("Calculator")

"""Display the main window"
with a little bit of padding"""
self.grid(padx=10,pady=10)
self.CreateWidgets()



def CreateWidgets(self):


self.btnDisplay = Button(self,text='1',command=lambda
n=1:self.Display(n))
self.btnDisplay.grid(row=3, column=0, padx=5, pady=5)

self.btnDisplay = Button(self,text='/',command=lambda
n="/":self.Display(n))
self.btnDisplay.grid(row=6, column=3, padx=5, pady=5)

Specify width=1 for both buttons.
 
S

skanemupp

how do i do that? i get this error:


self.btnDisplay = Button(self,text='1',command=lambda
n=1:self.Display(n))
self.btnDisplay.grid(row=3, column=0, padx=5, pady=5, width=1)

self.btnDisplay = Button(self,text='/',command=lambda
n="/":self.Display(n))
self.btnDisplay.grid(row=6, column=3, padx=5, pady=5, width=1)

Traceback (most recent call last):
File "C:\Users\saftarn\Desktop\guiexperiments
\calcguiworkingshort.py", line 37, in <module>
guiFrame = GUIFramework()
File "C:\Users\saftarn\Desktop\guiexperiments
\calcguiworkingshort.py", line 20, in __init__
self.CreateWidgets()
File "C:\Users\saftarn\Desktop\guiexperiments
\calcguiworkingshort.py", line 28, in CreateWidgets
self.btnDisplay.grid(row=3, column=0, padx=5, pady=5, width=1)
File "C:\Python25\lib\lib-tk\Tkinter.py", line 1859, in
grid_configure
+ self._options(cnf, kw))
TclError: bad option "-width": must be -column, -columnspan, -in, -
ipadx, -ipady, -padx, -pady, -row, -rowspan, or -sticky
 
G

Guilherme Polo

2008/4/5 said:
how do i do that? i get this error:



self.btnDisplay = Button(self,text='1',command=lambda
n=1:self.Display(n))

self.btnDisplay.grid(row=3, column=0, padx=5, pady=5, width=1)


self.btnDisplay = Button(self,text='/',command=lambda
n="/":self.Display(n))

self.btnDisplay.grid(row=6, column=3, padx=5, pady=5, width=1)

Add it to the Button widget, not to the grid method.
mybtn = Button(..., width=1)

Thanks,
 
M

Marc 'BlackJack' Rintsch

how do i do that?

Please include enough from the post you are answering to make the context
clear for someone who has not received the previous message.

BTW I don't think the `width` argument of the `Button()` call is the best
solution. Take a look at the options of the `grid()` call and figure out
how to tell that the content of the cell should fill it, so that the
Buttons in the grid automatically are equally sized in each row and column.

Ciao,
Marc 'BlackJack' Rintsch
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,782
Latest member
ThomasGex

Latest Threads

Top