Problem 2.1 - Menus hang command line

John Roth johnroth at
Thu Jun 7 13:39:26 EDT 2001

I've been trying to put together what should be a simple user
interface with a few entry fields and some drop down
selection boxes implemented as menu buttons.

The menu entries seem to fire when they are added to
the menu, and not when they are selected, which is exactly
the opposite of what I would expect. In addition, upon
exit (either the first or second time), the command line
hangs, and I have to ctl-alt-delete to get out of it. It
doesn't seem to matter if the interface actually manifests
or if the test goes on a syntax error: it still hangs the DOS box.

Python 2.1, Windows 98 second edition.

Code is:

# there are two major classes: ADateTime and ADateTimeUI.

from Tkinter import *

class ADateTimeUI:
    def __init__(self, parent, pADateTime):
        parent.title("Enter Date and Time") # This goes away eventually
        rownum = 0
        self.CalType = "Not Set" # default for testing
        Label(parent, text="Date:").grid(col=0, row=rownum)
        self.DateWidget = Entry(parent)
        self.DateWidget.grid(col=1, row = rownum, sticky=E+W)

        self.CalType = Menubutton(parent, text = "Gregorian")
        self.CalType.grid(col=2, row = rownum, sticky=E+W)
        ctMenu = Menu(self.CalType, tearoff=0)
        print ctMenu.config()
        ctMenu.add_command(label="Julian", command=self.CalCmd("Julian"))
        ctMenu.add_command(label="BCE", command=self.CalCmd("BCE"))
        ctMenu.add_command(label="AD", command=self.CalCmd("AD"))
        ctMenu.add_command(label="CE", command=self.CalCmd("CE"))
        ctMenu.add_command(label="NS", command=self.CalCmd("NS"))
        ctMenu.add_command(label="OS", command=self.CalCmd("OS"))

        rownum = 1
        Label(parent, text="Time:").grid(col=0, row=rownum)
        self.TimeWidget = Entry(parent)
        self.TimeWidget.grid(col=1, row = rownum, sticky=E+W)
        AMPMWidget = Label(parent, text="AMPM?")
        AMPMWidget.grid(col=2, row=rownum)
        rownum = 2
        Label(parent, text="Zone:").grid(col=0, row=rownum)
        self.ZoneWidget = Entry(parent)
        self.ZoneWidget.grid(col=1, row = rownum, sticky = E+W)
        TimeTypeWidget = Label(parent, text = "GMT")
        TimeTypeWidget.grid(col = 2, row=rownum)

        parent.columnconfigure(0, weight = 0)
        parent.columnconfigure(1, weight = 1)
        parent.columnconfigure(2, weight = 1)

    def CalCmd(self, which):
        self.CalType = which
        print which
        # might want to recalculate here, depending on if the date has been
        # filled in yet. If it has, then we should recalcualte the julian
        # in case we're displaying it.

if __name__ == "__main__":
    box = Tk()
    it = ADateTimeUI(box, None)
    box.title("ADateTime Dialog")
    print it.CalType

---End of Code---

By the way - I tried OptionMenu first, since it looked like exactly what
I wanted, and it didn't work at all. The button didn't have anything
printed on it.

John H. Roth Jr.

More information about the Python-list mailing list