By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,663 Members | 1,194 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,663 IT Pros & Developers. It's quick & easy.

Touble with Tkinter menus (code included)

P: n/a
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()

Jul 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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

Jul 18 '05 #2

P: n/a
Thanks!
Jul 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.