Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Touble with Tkinter menus (code included)

Reply
Thread Tools

Touble with Tkinter menus (code included)

 
 
James Ash
Guest
Posts: n/a
 
      10-19-2003
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()

 
Reply With Quote
 
 
 
 
Eric Brunel
Guest
Posts: n/a
 
      10-20-2003
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/tk...tion/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

 
Reply With Quote
 
 
 
 
James Ash
Guest
Posts: n/a
 
      10-20-2003
Thanks!
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Touble installing Yamicsoft Vista Manager digger odell Computer Support 3 09-21-2010 03:33 PM
Java - Importing from a Jar file hav touble with set CLASSPATH minifish Java 0 10-29-2008 02:12 AM
In touble, sincerely ask for kind advice. shuisheng C++ 8 09-05-2006 06:32 PM
Touble with passing a reference to vector of vectors of objects hardwareman C++ 4 06-28-2005 02:40 PM
Select menus above flyout menus? help? news.west.cox.net HTML 8 12-09-2004 12:54 PM



Advertisments