Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #100213 > unrolled thread

PyTk cascaded radiobuttons, howto?

Started bynickgeovanis@gmail.com
First post2015-12-09 16:17 -0800
Last post2015-12-10 10:27 +0100
Articles 3 — 2 participants

Back to article view | Back to comp.lang.python


Contents

  PyTk cascaded radiobuttons, howto? nickgeovanis@gmail.com - 2015-12-09 16:17 -0800
    Re: PyTk cascaded radiobuttons, howto? nickgeovanis@gmail.com - 2015-12-09 17:53 -0800
    tkinter cascaded menus, was Re: PyTk cascaded radiobuttons, howto? Peter Otten <__peter__@web.de> - 2015-12-10 10:27 +0100

#100213 — PyTk cascaded radiobuttons, howto?

Fromnickgeovanis@gmail.com
Date2015-12-09 16:17 -0800
SubjectPyTk cascaded radiobuttons, howto?
Message-ID<589c87de-5712-4efb-80a2-3a862b6dafd8@googlegroups.com>
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

[toc] | [next] | [standalone]


#100215

Fromnickgeovanis@gmail.com
Date2015-12-09 17:53 -0800
Message-ID<0bf9b6af-66d4-4ffc-b8dc-22842023cfd3@googlegroups.com>
In reply to#100213
This is of course using tkinter from python, PyTk is a misnomer. Python 3.4.2 wit tcl/tk 8.5 under CentOS 7.

[toc] | [prev] | [next] | [standalone]


#100224 — tkinter cascaded menus, was Re: PyTk cascaded radiobuttons, howto?

FromPeter Otten <__peter__@web.de>
Date2015-12-10 10:27 +0100
Subjecttkinter cascaded menus, was Re: PyTk cascaded radiobuttons, howto?
Message-ID<mailman.109.1449739694.12405.python-list@python.org>
In reply to#100213
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()

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web