473,396 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

tkinter menu bar problem

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

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

configMenu = Menu(menuBar, tearoff=0)
configMenu.add_command(label='Left Device Raw', command=setLeftRaw)
configMenu.add_command(label='Right Device Raw', command=setRightRaw)
etc

menuBar.add_cascade(label='Config', 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

Jul 18 '05 #1
3 5047
On Wed, 09 Feb 2005 11:35:40 GMT, John Pote <jo******@blueyonder.co.uk>
wrote:
I have a menu bar in a top level window as follows [snip code]
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.
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:
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(label='Quit', command=root.quit, background='red')


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...
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?


To "grey out" a menu item:

parentMenu.entryconfigure(itemIndex, 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 -
Jul 18 '05 #2
On Wed, 09 Feb 2005 11:35:40 GMT, John Pote <jo******@blueyonder.co.uk>
wrote:
I have a menu bar in a top level window as follows [snip code]
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.
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:
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(label='Quit', command=root.quit, background='red')


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...
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?


To "grey out" a menu item:

parentMenu.entryconfigure(itemIndex, 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 -
Jul 18 '05 #3
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='light blue')
menuBar.insert_cascade(MenuBar.CONFIG, label='Config', menu=configMenu,
background='light 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" <er*********@despammed.com> wrote in message
news:op**************@eb.pragmadev...
On Wed, 09 Feb 2005 11:35:40 GMT, John Pote <jo******@blueyonder.co.uk>
wrote:
I have a menu bar in a top level window as follows

[snip code]

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.


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:
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(label='Quit', command=root.quit, background='red')


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...
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?


To "grey out" a menu item:

parentMenu.entryconfigure(itemIndex, 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 -

Jul 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Josh | last post by:
Caution, newbie approaching... I'm trying to come up with a very simple Tkinter test application that consists of a window with a drop-down menu bar at the top and a grid of colored rectangles...
2
by: James Ash | last post by:
I'm writing a very simple and small Ptyhon/Tkinter application and I'm having trouble getting the menus to appear correctly. Rather than a name appearing on the menu bar, I see "()" instead. ...
1
by: Eric Brunel | last post by:
Hi all, I'm in the process of localizing a Tkinter application and I'm struggling with a problem for which I can't figure out a solution. The following code: -------------------------------...
1
by: midtoad | last post by:
I'm trying to display a GIF image in a label as the central area to a Tkinter GUI. The image does not appear, though a space is made for it. Why is this so? I notice that I can display a GIF...
6
by: Richard Lewis | last post by:
Hi there, I've got a tree control in Tkinter (using the ESRF Tree module) but I can't get it to layout how I want it. I'd like to have it so that it streches north/south (anchored to the top...
0
by: Stewart Midwinter | last post by:
I have a Tkinter app running on cygwin. It includes a Test menu item that does nothing more than fetch a directory listing and display it in a Toplevel window (I'd use a tkMessageBox showinfo...
2
by: Andrew Trevorrow | last post by:
Our app uses embedded Python to allow users to run arbitrary scripts. Scripts that import Tkinter run fine on Windows, but on Mac OS X there is a serious problem. After a script does "root = Tk()"...
2
by: Doran, Harold | last post by:
I am currently reading An Intro to Tkinter (1999) by F. Lundh. This doc was published in 1999 and I wonder if there is a more recent version. I've googled a bit and this version is the one I keep...
1
by: viv1tyagi | last post by:
Hi everyone ! ! ! I'm just a month old in the world of Python and trying to develop an application using Tkinter in which a new window pops out on a particular button press.The code for this new...
3
by: joshdw4 | last post by:
I hate to do this, but I've thoroughly exhausted google search. Yes, it's that pesky root window and I have tried withdraw to no avail. I'm assuming this is because of the methods I'm using. I...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.