newbie with major "lambda" problem (perhaps a scope problem as well)
Joe Potter
jm7potter at hotmail.com
Thu Jun 28 11:07:02 EDT 2001
On Wed, 27 Jun 2001 07:21:38 -0700, "John Roth" <johnroth at ameritech.net> wrote:
>
>"Joe Potter" <jm7potter at hotmail.com> wrote in message
>news:gkkjjts1msjq3ps19qs1aobi6m06jtscpc at 4ax.com...
>> On Tue, 26 Jun 2001 22:00:52 -0700, "John Roth" <johnroth at ameritech.net>
>wrote:
<snip>
>> Thanks John,
>>
>> I think I see it. If I can get a look at the solution to the code example
>> that I used in my reply to Chris Barker --- I'll have it made.
>>
>> Perhaps you can take a look at that example also?
>>
>> Thanks again.
>>
>> Regards, Joe
>
>You don't need to create a frame at all - the classes I write just go right
>ahead and start loading widgets into the parent widget, which is passed in as a
>parameter.
>
The code example came from Mark Lutz in his "Programming Python: 2nd Edition."
Unfortunately for me, he loves to use classes in nearly all of his examples. I tried
to "de-class" the code but failed to preserve functionality with my results.
>Setting up your class as a frame is somewhat better for code reuse, but it
>really depends on what you want to do with it If it's a one-shot, a frame is
>redundant. If it's a group of controls you're likely to want to use
>somewhere else, then putting it in a frame makes it much more portable.
>
>The following snippet shows one I wrote recently:
>
>class ADataEntryUI:
> def __init__(self, parent, frame):
> self.ParentClass = parent
> self.DateType = "Gregorian"
> self._DateVar = StringVar()
> self._DateError = ""
> self.TimeType = "AM"
> self._TimeVar = StringVar()
> self._TimeError = ""
>
>As you can see, it doesn't subclass anything!
>
>John Roth
>
John, I want to use the following code as an interface to learning to use Gadfly SQL
in Python. It works (sort of) now if one does not mind the function buttons scrolling
out of sight on even a small database.
What would really help --- is if you could advise me how in the world to put the
control buttons in the outer widget where they would not scroll ---- yet they would
still work.
If the work involved takes too much time and you do not care to look at it, that is
fine. But, if you could look at it I would really appreciate it.
In fact, if you could "de-class" the example it would be so much the better --- since
I would prefer to put off learning the mysteries of classes for a few more weeks.
Regardless, you have been very helpful and I thank you.
Regards, Joe
###################### code start (note will need a little txt file
##############################
import sys
from Tkinter import *
from tkMessageBox import askokcancel
import Pmw
class SumGrid(Frame):
def __init__(self, parent=None, numrow=5, numcol=5):
Frame.__init__(self, parent)
self.numrow = numrow # I am a frame container
self.numcol = numcol # caller packs or grids me
self.makeWidgets(numrow, numcol) # else only usable one way
def makeWidgets(self, numrow, numcol):
self.rows = []
for i in range(numrow):
cols = []
for j in range(numcol):
e = Entry(self, relief=RIDGE)
e.grid(row=i+1, column=j, sticky=NSEW)
e.insert(END, 'xx')
cols.append(e)
self.rows.append(cols)
Button(self, text='Print', command=self.onPrint).grid(row=0, column=0)
Button(self, text='Clear', command=self.onClear).grid(row=0, column=1)
Button(self, text='Load', command=self.onLoad).grid(row=0, column=2)
def onPrint(self):
for row in self.rows:
for col in row:
print col.get(),
print
print
def onClear(self):
for row in self.rows:
for col in row:
col.delete('0', END)
col.insert(END, '')
def onLoad(self):
import string
#from tkFileDialog import *
#file = askopenfilename()
file = "joe.txt"
if file:
for r in self.rows:
for c in r: c.grid_forget()
myfile = open(file, 'r')
filelines = myfile.readlines()
myfile.close()
self.numrow = len(filelines)
self.numcol = len(string.split(filelines[0]))
self.makeWidgets(self.numrow, self.numcol)
row = 0
for line in filelines:
fields = string.split(line)
for col in range(self.numcol):
self.rows[row][col].delete('0', END)
self.rows[row][col].insert(END, fields[col])
row = row+1
if __name__ == '__main__':
root = Tk()
root.title('test a button')
sf = Pmw.ScrolledFrame(root,
usehullsize = 1,
hull_width = 600,
hull_height = 300,
)
sf.pack(side = "top", padx = 10, pady = 6, fill = 'both', expand = 1)
# can we move the button calls to here, and hence --- pur them in root????
iframe = sf.interior()
SumGrid(iframe).pack()
mainloop()
######################## end code
##########################
You need a "joe.txt" file --- the below is as good as any
##############
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8
########################
########################
More information about the Python-list
mailing list