R
Robin Becker
I'm having trouble with defining a completely transparent bitmap
for use as a stipple in a canvas
import Tkinter
Tkinter._default_root.tk.call('image','create', 'bitmap', 'gray0',
'-background', '',
'-data', '#define gray0_width 1\n#define gray0_height 1\nstatic char
gray0_bits[] = {\n0x0\n};')
print 'image names', self.tk.call('image','names')
print 'image type', self.tk.call('image','type','gray0')
self.canv.create_rectangle("10i", "10i", "13.5i", "13.5i",
fill="blue",activestipple='gray0')
the prints seem to indicate that the bitmap is defined, but the canvas
create_rectangle fails
image names gray0
image type bitmap
Traceback (most recent call last):
File "C:\Tmp\test.py", line 67, in <module>
main()
File "C:\Tmp\test.py", line 62, in main
top = PDFMU()
File "C:\Tmp\test.py", line 59, in __init__
self.createWidgets()
File "C:\Tmp\test.py", line 44, in createWidgets
self.canv.create_rectangle("10i", "10i", "13.5i", "13.5i",
fill="blue",activestipple='gray0')
File "C:\Python\lib\lib-tk\Tkinter.py", line 2166, in create_rectangle
return self._create('rectangle', args, kw)
File "C:\Python\lib\lib-tk\Tkinter.py", line 2145, in _create
*(args + self._options(cnf, kw))))
_tkinter.TclError: bitmap "gray0" not defined
if I change gray0 to one of the predefined names eg gray12 then the
create_rectangle succeeds. The tk manual seems to suggest I should be
able to do this, but it doesn't seem to work even in tk. Is there a way
to define a stipple without a file?
for use as a stipple in a canvas
import Tkinter
Tkinter._default_root.tk.call('image','create', 'bitmap', 'gray0',
'-background', '',
'-data', '#define gray0_width 1\n#define gray0_height 1\nstatic char
gray0_bits[] = {\n0x0\n};')
print 'image names', self.tk.call('image','names')
print 'image type', self.tk.call('image','type','gray0')
self.canv.create_rectangle("10i", "10i", "13.5i", "13.5i",
fill="blue",activestipple='gray0')
the prints seem to indicate that the bitmap is defined, but the canvas
create_rectangle fails
image names gray0
image type bitmap
Traceback (most recent call last):
File "C:\Tmp\test.py", line 67, in <module>
main()
File "C:\Tmp\test.py", line 62, in main
top = PDFMU()
File "C:\Tmp\test.py", line 59, in __init__
self.createWidgets()
File "C:\Tmp\test.py", line 44, in createWidgets
self.canv.create_rectangle("10i", "10i", "13.5i", "13.5i",
fill="blue",activestipple='gray0')
File "C:\Python\lib\lib-tk\Tkinter.py", line 2166, in create_rectangle
return self._create('rectangle', args, kw)
File "C:\Python\lib\lib-tk\Tkinter.py", line 2145, in _create
*(args + self._options(cnf, kw))))
_tkinter.TclError: bitmap "gray0" not defined
if I change gray0 to one of the predefined names eg gray12 then the
create_rectangle succeeds. The tk manual seems to suggest I should be
able to do this, but it doesn't seem to work even in tk. Is there a way
to define a stipple without a file?