Some basic questions about Tkinter (probably v easy for experts!)
mrq at for.mat.bham.ac.uk
Wed Feb 7 09:02:43 EST 2001
On Wed, 7 Feb 2001, Fredrik Lundh wrote:
> have you read the introduction document? the first chapter
> seems to answer your questions:
I've tried to read the introduction document, but I found it rather
confusing, I'm afraid. I'm very new to this game and the use of lowercase
and uppercase variants of the same English word to denote almost the same
thing caused me problems. It is to avoid the confusion that I introduced
aardvark and armadillo as the names for my widgets below.
> > (4) Will the following correctly add a menu to my aardvark object?
> short answer: almost.
> > from sys import exit
> > armadillo = Menu(aardvark)
> this creates a menu component instance.
> > armadillo.add_cascade(label="File")
> this adds a submenu to the admadillo menubar. but you
> didn't pass in the submenu instance, so there's nothing to
> display when the user clicks on "File"...
> try this instead:
> filemenu = Menu(armadillo) # create a submenu
> armadillo.add_cascade(label="File", menu=filemenu)
Hold it - is "filemenu" a user defined name or is it built into Tkinter?
Would the following work equally well?
dongle = Menu(armadillo)
> > armadillo.add_command(lable="Exit", command=exit)
> if you fix the typo, this adds a command item to the armadillo
> menubar. when that item is selected, Tkinter calls sys.exit.
Oh good. (And "Oops!" about the typo.)
> if you want to add it to the file menu instead of the armadillo
> menubar, try this:
> filemenu.add_command(label="Exit", command=exit)
> finally, you need to attach the menu to your window:
What *exactly* does config do?
The Introduction document (p26) says "We use the config method to attach
it to the root window". But I couldn't find anywhere telling me what the
config method was.
Furthermore in the example on p26 of the document it has the following
menu = Menu(root)
But what happens if I call the menu bar on my root "aardvark"?
aardvark = Menu(root)
Does the next line contain "menu=aardvark", "aardvark=menu", or
> > If this isn't right - what is right, and more importantly *why* is it
> > right?
Ah yes - this is precisely the printed page that I have in front of me
that I'm not really understanding.
A related question is the Second Tkinter Program in that document (Hello,
Again). The command use to quite is frame.quit . Why is this used
instead of sys.exit() ? Am I right in thinking that frame is the
user defined name for the Frame, so if I wrote
aardvark = Frame(master)
I would use command = aardvark.quit
Thanks for the previous reply!
Dr. Martyn Quick (Research Fellow in Pure Mathematics)
University of Birmingham, Edgbaston, Birmingham, UK.
More information about the Python-list