[Tutor] help with Tkinter, please

Dick Moores rdm at rcblue.com
Sun Nov 26 02:23:39 CET 2006

At 01:37 PM 11/23/2006, Alan Gauld wrote:

>"Dick Moores" <rdm at rcblue.com> wrote
> > def compute_fact():
> >         value = int(entry_get())
> >   File "factTk1-a.py", line 22, in compute_fact
> >     value = int(entry_get())
> > NameError: global name 'entry_get' is not defined
> >
> > I'm so dumb I don't see how to define it.
>get is a method of the Entry widget.
>So the syntax is entry.get() not entry_get.

Sure did, Alan.

Some time has passed and I've made some progress. My question now is 
about the placement of buttons.

Here's part of my code:

root = Tk()
fram = Frame(root, bg = "black").pack()
Label(fram, text = "Enter a positive integer, n",).pack()
entry = Entry(fram, fg = "red", width = 30)

Button(fram, text="Compute n!", command=compute_fact).pack(side='top')
Button(fram, text="Compute n-cubed", command=compute_cube).pack(side="top")
Button(fram, text="Compute factors of n", 
Button(fram, text="Exit", command=sys.exit).pack(side="top")

#text = ScrolledText(fram)
text = ScrolledText(fram, bg = "cyan", fg = "red")
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.pack(side="top", expand = 1, fill = "both")


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?


Dick Moores

>Alan G.
>Tutor maillist  -  Tutor at python.org

More information about the Tutor mailing list