tkinter menu bar problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John Pote

    tkinter menu bar problem

    I have a menu bar in a top level window as follows

    menuBar = Menu(rootWin)
    menuBar.add_com mand( label='Quit', command=rootWin .quit)

    configMenu = Menu(menuBar, tearoff=0)
    configMenu.add_ command(label=' Left Device Raw', command=setLeft Raw)
    configMenu.add_ command(label=' Right Device Raw', command=setRigh tRaw)
    etc

    menuBar.add_cas cade(label='Con fig', menu=configMenu )

    rootWin.config( menu=menuBar)

    Q1 Cannot find a way of changing the menu bars background colour. When
    colour options are accepted they seem to be ignored. Is this a native look
    and feel characteristic of write once run anywhere, not yet implemented or
    possibly a bug.

    Q2 Some of the menu options in the config menu will not always be available
    depending on program state. How can individual items in such a menu be
    turned to faint gey to indicate their unavailability. Also a tick mark
    against an item would be useful to show the currently selected option. Is
    this possible?

    Regards,
    John Pote

    System: Win XP, Python 2.3.4



  • Eric Brunel

    #2
    Re: tkinter menu bar problem

    On Wed, 09 Feb 2005 11:35:40 GMT, John Pote <johnpote@bluey onder.co.uk>
    wrote:
    [color=blue]
    > I have a menu bar in a top level window as follows[/color]
    [snip code][color=blue]
    >
    > Q1 Cannot find a way of changing the menu bars background colour. When
    > colour options are accepted they seem to be ignored. Is this a native
    > look
    > and feel characteristic of write once run anywhere, not yet implemented
    > or
    > possibly a bug.[/color]

    Even if the tk man pages [1] don't mention it, it would not be surprising
    if the background option for menu items did not work on Windows, since
    many things seem to be "hardcoded" on this platform. I tested the
    following code on Linux; it works without problem and has the expected
    behaviour:
    [color=blue][color=green][color=darkred]
    >>> from Tkinter import *
    >>> root = Tk()
    >>> mb = Menu(root)
    >>> root.configure( menu=mb)
    >>> m = Menu(mb)
    >>> mb.add_cascade( label='Menu', menu=m)
    >>> m.add_command(l abel='Quit', command=root.qu it, background='red ')[/color][/color][/color]

    If it is what you did and if it doesn't work on Windows, it is likely that
    the background option for menu items is not supported for this platform...
    [color=blue]
    > Q2 Some of the menu options in the config menu will not always be
    > available
    > depending on program state. How can individual items in such a menu be
    > turned to faint gey to indicate their unavailability. Also a tick mark
    > against an item would be useful to show the currently selected option. Is
    > this possible?[/color]

    To "grey out" a menu item:

    parentMenu.entr yconfigure(item Index, state=DISABLED)

    To have menu items with a check-mark, use the add_checkbutton or
    add_radiobutton methods on the parent menu. Their use is similar to the
    Checkbutton and Radiobutton classes. See [1] for all available options.

    [1] http://www.tcl.tk/man/tcl8.4/TkCmd/menu.htm
    - Eric Brunel -

    Comment

    • Eric Brunel

      #3
      Re: tkinter menu bar problem

      On Wed, 09 Feb 2005 11:35:40 GMT, John Pote <johnpote@bluey onder.co.uk>
      wrote:
      [color=blue]
      > I have a menu bar in a top level window as follows[/color]
      [snip code][color=blue]
      >
      > Q1 Cannot find a way of changing the menu bars background colour. When
      > colour options are accepted they seem to be ignored. Is this a native
      > look
      > and feel characteristic of write once run anywhere, not yet implemented
      > or
      > possibly a bug.[/color]

      Even if the tk man pages [1] don't mention it, it would not be surprising
      if the background option for menu items did not work on Windows, since
      many things seem to be "hardcoded" on this platform. I tested the
      following code on Linux; it works without problem and has the expected
      behaviour:
      [color=blue][color=green][color=darkred]
      >>> from Tkinter import *
      >>> root = Tk()
      >>> mb = Menu(root)
      >>> root.configure( menu=mb)
      >>> m = Menu(mb)
      >>> mb.add_cascade( label='Menu', menu=m)
      >>> m.add_command(l abel='Quit', command=root.qu it, background='red ')[/color][/color][/color]

      If it is what you did and if it doesn't work on Windows, it is likely that
      the background option for menu items is not supported for this platform...
      [color=blue]
      > Q2 Some of the menu options in the config menu will not always be
      > available
      > depending on program state. How can individual items in such a menu be
      > turned to faint gey to indicate their unavailability. Also a tick mark
      > against an item would be useful to show the currently selected option. Is
      > this possible?[/color]

      To "grey out" a menu item:

      parentMenu.entr yconfigure(item Index, state=DISABLED)

      To have menu items with a check-mark, use the add_checkbutton or
      add_radiobutton methods on the parent menu. Their use is similar to the
      Checkbutton and Radiobutton classes. See [1] for all available options.

      [1] http://www.tcl.tk/man/tcl8.4/TkCmd/menu.htm
      - Eric Brunel -

      Comment

      • John Pote

        #4
        Re: tkinter menu bar problem

        Thanks for the reply. I now have radio buttons (with a nice tick!) on my
        menu that can be greyed out when disabled. I can also change the background
        colour of the individual buttons as you suggest.

        What I cannot do is change the background colour of the menu bar itself. The
        following code is accepted but the menu bar background stays resolutely
        light grey rather than light blue.

        rootWin = Tk()
        menuBar = MenuBar(rootWin , background='lig ht blue')
        menuBar.insert_ cascade(MenuBar .CONFIG, label='Config', menu=configMenu ,
        background='lig ht blue')

        The background options are being ignored and the window retains its standard
        windows colour scheme which I assume is overriding the background colour
        option. I guess my normal windows colour scheme (classic windows!) is not so
        bad and life is too short to tinker with this any more.

        Thanks again
        John Pote



        "Eric Brunel" <eric_brunel@de spammed.com> wrote in message
        news:opslxnemnr rqur0o@eb.pragm adev...[color=blue]
        > On Wed, 09 Feb 2005 11:35:40 GMT, John Pote <johnpote@bluey onder.co.uk>
        > wrote:
        >[color=green]
        >> I have a menu bar in a top level window as follows[/color]
        > [snip code][color=green]
        >>
        >> Q1 Cannot find a way of changing the menu bars background colour. When
        >> colour options are accepted they seem to be ignored. Is this a native
        >> look
        >> and feel characteristic of write once run anywhere, not yet implemented
        >> or
        >> possibly a bug.[/color]
        >
        > Even if the tk man pages [1] don't mention it, it would not be surprising
        > if the background option for menu items did not work on Windows, since
        > many things seem to be "hardcoded" on this platform. I tested the
        > following code on Linux; it works without problem and has the expected
        > behaviour:
        >[color=green][color=darkred]
        >>>> from Tkinter import *
        >>>> root = Tk()
        >>>> mb = Menu(root)
        >>>> root.configure( menu=mb)
        >>>> m = Menu(mb)
        >>>> mb.add_cascade( label='Menu', menu=m)
        >>>> m.add_command(l abel='Quit', command=root.qu it, background='red ')[/color][/color]
        >
        > If it is what you did and if it doesn't work on Windows, it is likely that
        > the background option for menu items is not supported for this platform...
        >[color=green]
        >> Q2 Some of the menu options in the config menu will not always be
        >> available
        >> depending on program state. How can individual items in such a menu be
        >> turned to faint gey to indicate their unavailability. Also a tick mark
        >> against an item would be useful to show the currently selected option. Is
        >> this possible?[/color]
        >
        > To "grey out" a menu item:
        >
        > parentMenu.entr yconfigure(item Index, state=DISABLED)
        >
        > To have menu items with a check-mark, use the add_checkbutton or
        > add_radiobutton methods on the parent menu. Their use is similar to the
        > Checkbutton and Radiobutton classes. See [1] for all available options.
        >
        > [1] http://www.tcl.tk/man/tcl8.4/TkCmd/menu.htm
        > - Eric Brunel -[/color]


        Comment

        Working...