Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Peter Otten <__peter__@web.de> Newsgroups: comp.lang.python Subject: tkinter cascaded menus, was Re: PyTk cascaded radiobuttons, howto? Date: Thu, 10 Dec 2015 10:27:53 +0100 Organization: None Lines: 57 Message-ID: References: <589c87de-5712-4efb-80a2-3a862b6dafd8@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Trace: news.uni-berlin.de KiyuYXaRUYzh6CPB7mTEKQgqIGnyAAxv/j6pwT2XTgnQ== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'root': 0.04; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:howto': 0.09; 'tcl/tk': 0.09; 'python': 0.10; 'anyway': 0.11; '2.7': 0.13; 'skip:f 30': 0.15; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'received:t-ipconnect.de': 0.16; 'wrote:': 0.16; 'either.': 0.22; 'skip:$ 20': 0.22; 'tkinter': 0.22; 'errors': 0.23; 'this:': 0.23; 'import': 0.24; 'examples': 0.24; 'header:User-Agent:1': 0.26; 'example': 0.26; 'header:X-Complaints-To:1': 0.26; 'skip:m 30': 0.27; 'skip:e 30': 0.27; 'correct': 0.28; 'usable': 0.29; 'creating': 0.30; 'folder': 0.30; 'skip:. 10': 0.32; 'source': 0.33; 'skip:/ 20': 0.33; 'add': 0.34; 'skip:c 30': 0.35; 'something': 0.35; 'there': 0.36; 'to:addr:python-list': 0.36; 'subject:?': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'doing': 0.38; 'build': 0.40; 'to:addr:python.org': 0.40; 'received:de': 0.40; 'save': 0.60; 'email addr:gmail.com': 0.62; 'skip:n 10': 0.62; 'difficulty': 0.66; 'here': 0.66; 'skip:$ 10': 0.67; '...and': 0.84 X-Injected-Via-Gmane: http://gmane.org/ X-Gmane-NNTP-Posting-Host: p57bd8616.dip0.t-ipconnect.de User-Agent: KNode/4.13.3 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:100224 nickgeovanis@gmail.com wrote: > Using python 3.4.2. > Tcl/tk example here is from /usr/share/tk8.5/demos/widget and > .../menu.tcl. The way tcl/tk adds cascaded radiobuttons to a menu is like > this: set m $w.menu.cascade > $w.menu add cascade -label "Cascades" -menu $m -underline 0 > .... > $m add cascade -label "Radio buttons" -menu $w.menu.cascade.radio... > set m $w.menu.cascade.radio > $m add radio -label "Roman" -variable style... > $m add radio -label "Italic" -variable style... > > ...and so on. > > My difficulty doing the same in PyTk is the following: When creating that > uppermost cascade, you do something like menu.add_cascade(label = > "Cascades") ...but there is no ability to save a usable reference to that > top-level cascade. If I do so anyway and add a radiobutton to it, nothing > appears, no errors either. What is the correct way to cascade radiobuttons > from a cascaded menu in PyTk? Thanks....Nick You build the inner menu and then add it to the outer. After looking into the examples in the Demo/tkinter folder of the Python 2.7 source distribution I came up with the following: import tkinter from tkinter import Menu root = tkinter.Tk() menubar = Menu(root) editmenu = Menu(menubar) editmenu.add_command(label="Cut") editmenu.add_command(label="Copy") editmenu.add_command(label="Paste") fontmenu = Menu(editmenu, name="font") fontmenu.add_command(label="Family") fontmenu.add_command(label="Size") editmenu.add_cascade(label="Font", menu=fontmenu) colormenu = Menu(editmenu, name="color") colormenu.add_radiobutton(label="Red") colormenu.add_radiobutton(label="Yellow") colormenu.add_radiobutton(label="Blue") fontmenu.add_cascade(label="Color", menu=colormenu) menubar.add_cascade(label="Edit", menu=editmenu) root["menu"] = menubar root.mainloop()