classification
Title: Py30a5: Tk Menu Alt-f behaves differently Linux vs Windows
Type: behavior Stage:
Components: Versions: Python 3.0
process
Status: closed Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: gpolo, mark
Priority: normal Keywords:

Created on 2008-05-09 21:51 by mark, last changed 2008-05-24 12:55 by gpolo. This issue is now closed.

Messages (4)
msg66492 - (view) Author: Mark Summerfield (mark) * Date: 2008-05-09 21:51
#Python 3.0a5 (py3k:62932M, May  9 2008, 16:23:11) [MSC v.1500 32 bit
#(Intel)] on win32
#
# If you run this tiny program on Linux and press Alt+F (Alt-f in Tk 
# terminology) the File menu pops up as expected. But run it on
# Windows Home XP and nothing happens when you press Alt+F.
# The problem may be with the code below since IDLE works fine on
# Windows, in which case sorry!
# However, Grayson's AppB/menu.py example (with suitably fixed print
# statements since it was writtend for Py2) is exactly the same: 
# works fine on Linux but Alt+key does not invoke the menus on Windows.
from Tkinter import *

class MainWindow:

    def __init__(self, parent):
        self.parent = parent

        menuBar = Frame(self.parent, relief=RAISED, borderwidth=2)
        menuBar.pack(anchor=N, fill=X)
        fileMenu = Menubutton(menuBar, text="File", underline=0)
        fileMenu.pack(side=LEFT)
        fileMenu.menu = Menu(fileMenu, tearoff=False)
        for label, command in (
                ("New...", self.fileNew),
                ("Open...", self.fileOpen),
                ("Quit", self.fileQuit)):
            fileMenu.menu.add_command(label=label, command=command)
        fileMenu["menu"] = fileMenu.menu
        menuBar.tk_menuBar(fileMenu)

    def fileNew(self, *args):
        print("fileNew", args)

    def fileOpen(self, *args):
        print("fileOpen", args)

    def fileQuit(self, *args):
        self.parent.destroy()

root = Tk()
window = MainWindow(root)
root.protocol("WM_DELETE_WINDOW", window.parent.destroy)
root.mainloop()
msg66847 - (view) Author: Mark Summerfield (mark) * Date: 2008-05-15 07:45
This bug can be worked around by using the more modern style of menu
creation. If the program that exhibits the bug has its __init__()
replaced as follows it works correctly on both Linux and Windows:

    def __init__(self, parent):
        self.parent = parent
        menu = Menu(self.parent)
        self.parent.config(menu=menu)
        fileMenu = Menu(menu)
        for label, command in (
                ("New...", self.fileNew),
                ("Open...", self.fileOpen),
                ("Quit", self.fileQuit)):
            fileMenu.add_command(label=label, command=command)
        menu.add_cascade(label="File", menu=fileMenu, underline=0)
msg67295 - (view) Author: Guilherme Polo (gpolo) * (Python committer) Date: 2008-05-24 12:51
Using a frame and menubutton for creating a menubar has been deprecated
for a long time. I tried finding when exactly it got "marked as
deprecated", but I found just this page http://wiki.tcl.tk/4055 which
says about a decade ago.
msg67297 - (view) Author: Guilherme Polo (gpolo) * (Python committer) Date: 2008-05-24 12:55
I just got an information here.. The new way is the recommended way
since Tk 8.0
History
Date User Action Args
2008-05-24 12:55:32gpolosetmessages: + msg67297
2008-05-24 12:51:41gpolosetstatus: open -> closed
nosy: + gpolo
messages: + msg67295
2008-05-15 07:45:19marksetmessages: + msg66847
2008-05-09 21:51:55markcreate