At 06:54 PM 11/26/2006, John Fouhy wrote: >On 27/11/06, Dick Moores <[EMAIL PROTECTED]> 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:
A lot better! And now that I understand columnspan, I was able to move the buttons around and configure them a bit more. I'm quite satisfied now. For this program it seems I won't be needing to employ the nested frames suggested by Alan and Kent. But of course I'll try those anyway, just to learn about them. I have a question about the "EXIT" button's command, command=sys.exit. It fails to quit the program when I've entered too large an integer for factoring, or for prime testing, and I don't want to wait any more for the result. When I'm running the program from my Win XP console, I can quit with a simple Ctrl+C, but this won't be available to the friend I may send the executable to. Is it possible to build in a way to smoothly interrupt, say, a factoring process that's taking too long? Thanks very much, John. Dick >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", > fg="#996666").grid(row=0,column=1,sticky=W) > >entry = Entry(fram, fg="red", bg="#DCDCDC", width = 30) >entry.focus_set() >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) >b1.grid(row=2,column=0,sticky=W) > >b2=Button(fram, text="Partially spell n", fg="black", bg="white", > width = 19) >b2.grid(row=2,column=1,sticky=W) > >b3=Button(fram, text="Compute factors of n", bg="#D3D3D3", > fg="yellow", width = 19) >b3.grid(row=2,column=2,sticky=W) > >b4=Button(fram, text="Find primes in [n, n+99]", bg="yellow", >fg="red", width = 19) >b4.grid(row=2,column=3,sticky=W) > >long_text = "See the largest number that can be spelled" >b5=Button(fram, text=long_text, fg="green", bg="#BF6AF5", width = 19) >b5.grid(row=3,column=0,columnspan=3,sticky=E+W) > >b6=Button(fram, text="EXIT", fg="white", bg="red", width = >19,command=sys.exit) >b6.grid(row=3,column=3,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=4,column=0,columnspan=4,sticky=N+S+E+W) > >mainloop() >_______________________________________________ >Tutor maillist - Tutor@python.org >http://mail.python.org/mailman/listinfo/tutor _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor