473,385 Members | 2,028 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Touble with Tkinter menus (code included)

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
2 2084
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
Thanks!
Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Josh | last post by:
Caution, newbie approaching... I'm trying to come up with a very simple Tkinter test application that consists of a window with a drop-down menu bar at the top and a grid of colored rectangles...
2
by: Stewart Midwinter | last post by:
I would like to link the contents of three OptionMenu lists. When I select an item from the first list (call it continents), the contents of the 2nd list (call it countries) would update. And in...
0
by: Dan Greenblatt | last post by:
I know this can be done for context menus with the 'post' command.... What I'm trying to do, though, is programmatically post non-contextual menus (i.e. menus that exist on a horizontal menu bar...
6
by: Bob Greschke | last post by:
Root.option_add("*?????*font", "Helvetica 12 bold") Want to get rid of the "font =": Widget.add_cascade(label = "File", menu = Fi, font = "Helvetica 12 bold") Does anyone know what ?????...
0
by: Stewart Midwinter | last post by:
I have a Tkinter app running on cygwin. It includes a Test menu item that does nothing more than fetch a directory listing and display it in a Toplevel window (I'd use a tkMessageBox showinfo...
2
by: ishtar2020 | last post by:
Hi everybody I'd appreciate some help on creating a tear off menu with TkInter. I've been reading some documentation but still no luck. Please don't get confused: when I mean "tear off" menu I...
2
by: Andrew Trevorrow | last post by:
Our app uses embedded Python to allow users to run arbitrary scripts. Scripts that import Tkinter run fine on Windows, but on Mac OS X there is a serious problem. After a script does "root = Tk()"...
4
by: Gigs_ | last post by:
class MenuDemo(Frame): def __init__(self, parent=None): Frame.__init__(self, parent) self.pack(expand=YES, fill=BOTH) self.createWidgets() def createWidgets(self): self.makeMenuBar()...
44
by: bg_ie | last post by:
Hi, I'm in the process of writing some code and noticed a strange problem while doing so. I'm working with PythonWin 210 built for Python 2.5. I noticed the problem for the last py file...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.