473,795 Members | 2,834 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(mas ter)
master.title("T imecard, Implemented in Cygwin supplied Python!")
master.maxsize( 1000, 400)
frame.pack()

self.b = Button(frame, text="Clock In", width=8, command=self.ca llback)
self.b.pack(sid e=LEFT, padx=2, pady=2)

self.b = Button(frame, text="Clock Out", width=8, command=self.ca llback)
self.b.pack(sid e=LEFT, padx=2, pady=2)

self.b = Button(frame, text="Report", width=8, command=self.ca llback)
self.b.pack(sid e=LEFT, padx=2, pady=2)

self.menubar = Menu(master)

self.filemenu=M enu(self.menuba r)
self.filemenu.a dd_command(mast er, label="Exit", command=self.ca llback)
self.menubar.ad d_cascade(maste r, label="File", menu=self.filem enu)

master.config(m enu=self.menuba r)

root = Tk()

app = App(root)
root.mainloop()

Jul 18 '05 #1
2 2103
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(mas ter)
master.title("T imecard, Implemented in Cygwin supplied Python!")
master.maxsize( 1000, 400)
frame.pack()

self.b = Button(frame, text="Clock In", width=8, command=self.ca llback)
self.b.pack(sid e=LEFT, padx=2, pady=2)

self.b = Button(frame, text="Clock Out", width=8, command=self.ca llback)
self.b.pack(sid e=LEFT, padx=2, pady=2)

self.b = Button(frame, text="Report", width=8, command=self.ca llback)
self.b.pack(sid e=LEFT, padx=2, pady=2)

self.menubar = Menu(master)

self.filemenu=M enu(self.menuba r)
self.filemenu.a dd_command(mast er, label="Exit", command=self.ca llback)
self.menubar.ad d_cascade(maste r, label="File", menu=self.filem enu)
No need for master in the two previous calls: doing just

self.filemenu.a dd_command(labe l="Exit", command=self.ca llback)
self.menubar.ad d_cascade(label ="File", menu=self.filem enu)

solves the problem.

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

master.config(m enu=self.menuba r)

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
5987
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 filling the remainder of the window. Mind you, this is a contrived test application to help me understand Tkinter and Python, not an actual application yet. I've trivially subclassed Tkinter.Canvas into ColorCanvas, added a bunch of ColorCanvases...
2
4638
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 turn the contents of the 3rd list (call it states would be updated by a change in the 2nd list. If anyone can share a recipe or some ideas, I'd be grateful! Here's some sample code that displays three OptionMenus, but doesn't update the list...
0
1099
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 at the top of my application window) in the correct place. So if I have five different menus (i guess these are menubuttons?) placed horizontally on my menu bar, and the third one is 'Actions', what is the best way to determine the x and y...
6
4500
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 ????? should be to control the font of the cascade menus (the labels on the menu bar)? "*Menu*font" handles the part that drops down, but I can't come up with the menu bar labels part. Thanks!
0
2360
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 widget, but for some reason the text is invisible on cygwin). After I close the Toplevel widget, all of the menus in my app behave as though they have no contents to them, i..e I can press on the File menu button, and see it depress, but the Exit...
2
2844
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 don't mean a drop-down or a pop-up menu, but those options which yield to another batch of sub-options when scrolled over, (as for example, the File->New option from internet explorer).
2
5206
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()" our app's menus are permanently changed in the following way: - The top item in the application menu changes to "About Tcl & Tk...". - The Quit item is disabled. - The File and Edit menus are completely replaced. - All further menus (except...
4
1888
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() self.makeToolBar() L = Label(self, text='Menu and Toolbar demo')
44
5010
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 processed by this script, where the concerned tmp file is only actually written to when PythonWin is closed. In other words, after I run this script, one of the generated tmp files has a size of 0kB. I then close PythonWin and it is then written to.
0
9522
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10443
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10216
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10002
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7543
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6783
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5437
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5565
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2921
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.