Touble with Tkinter menus (code included)

Discussion in 'Python' started by James Ash, Oct 20, 2003.

  1. James Ash

    James Ash Guest

    I'm writing a very simple and small Ptyhon/Tkinter application and I'm
    having trouble getting the menus to appear correctly. Rather than a name
    appearing on the menu bar, I see "()" instead. Clicking on these "()" does
    nothing (other than changing the appearance of them to indicated they've
    been pressed).

    I'm using Python 2.2.3 on Win2K, using a release downloaded from one
    of the Cygwin mirrors.

    This is most likely a simple mistake on my part, but I can't find it. I'm new
    to Python and Tkinter both.

    Any help appreciated!
    Jim


    #! /usr/bin/env python

    # $Id$
    #
    # File: timecard.py

    import string


    from Tkinter import *



    class App:

    def callback(self):
    print "called the callback!"

    def __init__(self, master):
    frame=Frame(master)
    master.title("Timecard, Implemented in Cygwin supplied Python!")
    master.maxsize(1000, 400)
    frame.pack()

    self.b = Button(frame, text="Clock In", width=8, command=self.callback)
    self.b.pack(side=LEFT, padx=2, pady=2)

    self.b = Button(frame, text="Clock Out", width=8, command=self.callback)
    self.b.pack(side=LEFT, padx=2, pady=2)

    self.b = Button(frame, text="Report", width=8, command=self.callback)
    self.b.pack(side=LEFT, padx=2, pady=2)

    self.menubar = Menu(master)

    self.filemenu=Menu(self.menubar)
    self.filemenu.add_command(master, label="Exit", command=self.callback)
    self.menubar.add_cascade(master, label="File", menu=self.filemenu)

    master.config(menu=self.menubar)

    root = Tk()

    app = App(root)
    root.mainloop()
    James Ash, Oct 20, 2003
    #1
    1. Advertising

  2. James Ash

    Eric Brunel Guest

    James Ash wrote:
    > I'm writing a very simple and small Ptyhon/Tkinter application and I'm
    > having trouble getting the menus to appear correctly. Rather than a name
    > appearing on the menu bar, I see "()" instead. Clicking on these "()" does
    > nothing (other than changing the appearance of them to indicated they've
    > been pressed).
    >
    > I'm using Python 2.2.3 on Win2K, using a release downloaded from one
    > of the Cygwin mirrors.
    >
    > This is most likely a simple mistake on my part, but I can't find it. I'm new
    > to Python and Tkinter both.
    >
    > Any help appreciated!
    > Jim
    >
    >
    > #! /usr/bin/env python
    >
    > # $Id$
    > #
    > # File: timecard.py
    >
    > import string
    >
    >
    > from Tkinter import *
    >
    >
    >
    > class App:
    >
    > def callback(self):
    > print "called the callback!"
    >
    > def __init__(self, master):
    > frame=Frame(master)
    > master.title("Timecard, Implemented in Cygwin supplied Python!")
    > master.maxsize(1000, 400)
    > frame.pack()
    >
    > self.b = Button(frame, text="Clock In", width=8, command=self.callback)
    > self.b.pack(side=LEFT, padx=2, pady=2)
    >
    > self.b = Button(frame, text="Clock Out", width=8, command=self.callback)
    > self.b.pack(side=LEFT, padx=2, pady=2)
    >
    > self.b = Button(frame, text="Report", width=8, command=self.callback)
    > self.b.pack(side=LEFT, padx=2, pady=2)
    >
    > self.menubar = Menu(master)
    >
    > self.filemenu=Menu(self.menubar)
    > self.filemenu.add_command(master, label="Exit", command=self.callback)
    > self.menubar.add_cascade(master, label="File", menu=self.filemenu)


    No need for master in the two previous calls: doing just

    self.filemenu.add_command(label="Exit", command=self.callback)
    self.menubar.add_cascade(label="File", menu=self.filemenu)

    solves the problem.

    Please refer to http://www.pythonware.com/library/tkinter/introduction/index.htm
    for further details.

    >
    > master.config(menu=self.menubar)
    >
    > root = Tk()
    >
    > app = App(root)
    > root.mainloop()
    >


    HTH
    --
    - Eric Brunel <eric dot brunel at pragmadev dot com> -
    PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com
    Eric Brunel, Oct 20, 2003
    #2
    1. Advertising

  3. James Ash

    James Ash Guest

    Thanks!
    James Ash, Oct 20, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. news.west.cox.net

    Select menus above flyout menus? help?

    news.west.cox.net, Dec 8, 2004, in forum: HTML
    Replies:
    8
    Views:
    795
  2. Dan Greenblatt

    Programmatically posting tkinter menus

    Dan Greenblatt, Aug 11, 2004, in forum: Python
    Replies:
    0
    Views:
    284
    Dan Greenblatt
    Aug 11, 2004
  3. hardwareman
    Replies:
    4
    Views:
    365
    Peter Julian
    Jun 28, 2005
  4. shuisheng
    Replies:
    8
    Views:
    375
    Jim Langston
    Sep 5, 2006
  5. minifish
    Replies:
    0
    Views:
    431
    minifish
    Oct 29, 2008
Loading...

Share This Page