Tkinter: disable a item in a Menubar

Klaus Bruns klaus.bruns at teleatlas.com
Wed Jun 7 05:09:34 EDT 2000


Hi all,

I want to change the state of an item in a Menubar, but I don't now how
to do.
For example: in the Menu 'File' there is a funktion to open and save a
file. After using the 'open' funktion this funktion is disable till
using the 'save' funktion.

I use Pmw for creating the Menubar:

import Pmw
from Tkinter import *

class mymenu:
   def __init__(root):
	Pmw.initialise(root)
	self.balloon=Pmw.Balloon(root)
	self.menuBar=Pmw.MenuBar(root,hull_relief=RAISED,hull_borderwidth=1,
                                 balloon=self.balloon)
        self.menuBar.pack(fill=X)
        self.menuBar.addmenu('FILE','open and save files')
	self.menuBar.addmenuitem('FILE','command','open a file',label='open',
				  command=self.open_file)
	self.menuBar.addmenuitem('FILE','command',save a file',label='save',
				  command=self.save_file)
	
   def open_file(self):
	file  = open(filename)
	## here I want to change the state of 'open' to DISABLED

   def save_file(self):
	## do something to save the file
	## and change the state of 'save' to DISABLED and 'open' to Normal

root = TK()
mymenu(root)
root.mainloop()

Can anyone help me?

	Klaus



More information about the Python-list mailing list