[Tutor] help with Tkinter, please
Dick Moores
rdm at rcblue.com
Mon Nov 27 03:37:29 CET 2006
At 08:59 AM 11/26/2006, Michael Lange wrote:
>On Sat, 25 Nov 2006 17:23:39 -0800
>Dick Moores <rdm at rcblue.com> wrote:
>
> > I've done a lot of fiddling around with setting "side=left", and
> > trying to put all the buttons inside a second Frame inside the first
> > one, but I can't get the layout I want, which is the Label on top of
> > the Entry, then a row of the first 3 buttons (which respectively
> > trigger 3 different computations on the integer the user enters).
> > Then below that, the Exit button, with the Text widget at the bottom.
> > How to do this? Is it impossible with the pack() method?
> >
>
>It is certainly not impossible, as long as you do not mind creating
>a bunch of extra Frames, however to me this really sound like a
>job for grid() .
>You could simply use grid(row=<xx> , column=0, columnspan=2)
>for the widgets that should use the whole window's width and grid
>the 3 buttons into columns 0, 1 and 2 .
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.
When I use pack(), the buttons are nicely centered, but lined up
vertically, one above the other. Maybe I can live with that. But I'd
still like to learn how to use grid() well.
Dick
============================================================
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",
fg="#996666").grid(row=0,column=3)
entry = Entry(fram, fg="red", bg="#DCDCDC", width = 30)
entry.focus_set()
entry.grid(row=2,column=3, padx=5, pady=5)
b1=Button(fram, text="Compute n!", bg="black", fg="white", width =
19,command=compute_fact)
b1.grid(row=4,column=0,columnspan=2,sticky=W)
b2=Button(fram, text="Partially spell n", fg="black", bg="white",
width = 19,command=integer_spell)
b2.grid(row=4,column=1,columnspan=2,sticky=W)
b3=Button(fram, text="Compute factors of n", bg="#D3D3D3",
fg="yellow", width = 19,command=compute_factors)
b3.grid(row=4,column=2,columnspan=2,sticky=W)
b4=Button(fram, text="Find primes in [n, n+99]", bg="yellow",
fg="red", width = 19,command=primes_in_interval)
b4.grid(row=4,column=3,columnspan=2,sticky=W)
long_text = "See the largest number that can be spelled"
b5=Button(fram, text=long_text, fg="green", bg="#BF6AF5", width =
19,command=largest_number)
b5.grid(row=4,column=4,columnspan=2,sticky=W)
b6=Button(fram, text="EXIT", fg="white", bg="red", width = 19,command=sys.exit)
b6.grid(row=4,column=5,columnspan=2,sticky=W)
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.")
text.grid(row=5,columnspan=7,sticky=S)
mainloop()
==================================================================
More information about the Tutor
mailing list