[Tutor] help with Tkinter, please

John Fouhy john at fouhy.net
Mon Nov 27 03:54:50 CET 2006

On 27/11/06, Dick Moores <rdm at rcblue.com> wrote:
> Well, I'm having a terrible time with grid(). I do have the 6 buttons
> in the same row, but they're a real mess. Someone please run this and
> tell me how to get them looking better.

I'm not certain exactly what layout you want, but have a look at this
to see if it looks any better:

I think you were a bit confused about the role of columnspan.  If you
say .grid(row=R, column=C, columnspan=2) then the widget you are
gridding will occupy (row R, column C) _and_ (row R, column C+1) (ie:
it spans two columns).

from Tkinter import *

root = Tk()
root.option_add('*font', ('verdana', 11))
root.title("Fun with integers")
fram = Frame(root).grid()

Label(fram, text="Enter a positive integer, n",

entry = Entry(fram, fg="red", bg="#DCDCDC", width = 30)
entry.grid(row=1,column=1, padx=5, pady=5,sticky=E+W)

b1=Button(fram, text="Compute n!", bg="black", fg="white", width = 19)

b2=Button(fram, text="Partially spell n", fg="black", bg="white",
                 width = 19)

b3=Button(fram, text="Compute factors of n", bg="#D3D3D3",
                 fg="yellow", width = 19)

b4=Button(fram, text="Find primes in [n, n+99]", bg="yellow",
fg="red", width = 19)

long_text = "See the largest number that can be spelled"
b5=Button(fram, text=long_text, fg="green", bg="#BF6AF5", width = 19)

b6=Button(fram, text="EXIT", fg="white", bg="red", width = 19,command=sys.exit)

#text = ScrolledText(fram, bg = "cyan", fg = "#330000", height=18)
text = Text(fram)
text.insert(END, "n-factorial or n-cubed will appear here.\n\n")
text.insert(END, 'And again, with commas inserted.\n\n')
text.insert(END, "And yet again, in scientific notation.")


More information about the Tutor mailing list