Why default parameter value not working? 
Author Message
 Why default parameter value not working?

The following code is supposed to be the start of a 'row' widget for
use in a spread-sheet-like context:

from Tkinter import *

class Row(Frame):

    def __init__(self, title="Title", cells=5, titlewidth=30,
cellwidth=5, height=1, **options):
        print "Title is", title
        Frame.__init__(self, options)
        label = Label(self, text=title, width=titlewidth, height=height,
background='white')
        label.grid(row=0, column=0)
        _cells = [None] * cells
        for i in range(cells):
            _cells[i] = Label(self, width=cellwidth, height=height,
borderwidth=3, relief='groove')
            _cells[i].grid(row=0, column=i+1)

win = Tk()
r = Row(win)
r.pack()
mainloop()

Works fine, except that for some reason the 'title' parameter for r is
not being correctly set to the default value of "Title", and I can't
really figure out why...

Thanks,
Ken
========================================
Kenneth McDonald
Genome Sequencing Center
Washington University School of Medicine

Phone: 314-286-1831
========================================



Tue, 22 Aug 2000 03:00:00 GMT  
 Why default parameter value not working?

Quote:
Ken Mcdonald writes:

 > class Row(Frame):
 >
 >     def __init__(self, title="Title", cells=5, titlewidth=30,
...
 > win = Tk()
 > r = Row(win)

Ken,
  Your Row.__init__() doesn't seem to be handling the parameter you're
passing in.  title is taking the value win and so life becomes messy.
Try calling just Row().

  -Fred

--
Fred L. Drake, Jr.

Corporation for National Research Initiatives
1895 Preston White Drive    Reston, VA  20191



Tue, 22 Aug 2000 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Why default values not taken?

2. extending ruby: defining method with default parameters value...

3. Default values for named formal parameters

4. Default value on signal parameter of a procedure

5. Extracting method parameter and default-values?

6. default values of function parameters (construtors)

7. Non-intuitive treatment of empty list as default parameter value on class method

8. Mutable default values for function parameters

9. proc default values for parameters

10. Default Select Button not working

11. compiler option for local variables to default to automatic not working

12. C4 - Autoincrementing default values for multi-valued template symbols

 

 
Powered by phpBB® Forum Software