472,958 Members | 2,136 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 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 2055
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: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...

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.