Image on disabled button

Richard Townsend nospam at here.com
Tue Sep 9 15:35:50 EDT 2003


>
> Do you have a sample bitmap and code snipper (Tcl/Tk or Tkinter) that
> one can repro this with?  There were some fixes that went in for
> compound buttons (those that display both image and text), but I don't
> think anything changed for regular bitmaps.
>

Hi Jeff,

I have done further experiments. The original problem occurred on HP-UX11i.
I cannot reproduce it on Linux (SuSE 8.2).
Both systems were running Tk-Tcl 8.4.4 plus Python 2.3 (both built from
source). It also happens with Tk-Tcl 8.4.3.

However it DOES also occur on Windows 2000, running the standard Python 2.3
installation.

Example code is below.

If I uncomment the Button's width and height options, then the effect is
even more marked (the stipple is even further offset to the northeast).

(From memory) the following options added after creating the root window
prevent the bug occurring on HP-UX11i

self.root.option_add('*background', 'grey75')
self.root.option_add('*disabledBackground', '')

however they do not appear to have any effect on Windows.

----------------------------------------------------------------------------
--------------------------------------------
# icon_button.py
----------------------------------------------------------------------------
--------------------------------------------

import Tkinter

class Demo:

    def __init__(self):

        self.root = Tkinter.Tk()

        self.bitmap = Tkinter.BitmapImage(file='square.xbm',
                                          foreground='black')


        self.button = Tkinter.Button(self.root,
                                     image=self.bitmap,
                                     #width=50,
                                     #height=50,
                                     anchor='center')
        self.button.pack(side='top', padx=20, pady=20)

        frame= Tkinter.Frame(self.root)
        frame.pack(side='top', expand=True, fill='both')

        b = Tkinter.Button(frame, text='Disable', command=self.disable)
        b.pack(side='left')

        b = Tkinter.Button(frame, text='Enable', command=self.enable)
        b.pack(side='left')

        b = Tkinter.Button(frame, text='Quit', command=self.quit)
        b.pack(side='left')

        self.root.mainloop()


    def disable(self):

        self.button.configure(state='disabled')


    def enable(self):

        self.button.configure(state='normal')


    def quit(self):

        self.root.quit()



if __name__ == '__main__':

    Demo()


----------------------------------------------------------------------------
--------------------------------------------
square.xbm
----------------------------------------------------------------------------
--------------------------------------------

#define square.xbm_width 32
#define square.xbm_height 32
static unsigned char square.xbm_bits[] = {
   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};







More information about the Python-list mailing list