Re: cut & paste text between tkinter widgets

2005-08-04 Thread Repton
Christopher Subich wrote:
> In experimenting with this, I found a slight... fun issue involved in
> this.  Selection_get is the correct method to call, but it doesn't quite
> work out of the box.
>  >>> g.selection_get()
> Traceback (most recent call last):
>File "", line 1, in ?
>File "C:\Python24\Lib\lib-tk\Tkinter.py", line 574, in selection_get
>  return self.tk.call(('selection', 'get') + self._options(kw))
> _tkinter.TclError: PRIMARY selection doesn't exist or form "STRING" not
> defined
>
> This poses a small problem.  I'm not sure whether this is a
> Win32-related issue, or it's because the PRIMARY selection isn't fully
> configured.

You need to select something first :-)

>>> from Tkinter import *
>>> tk = Tk(); e = Entry(tk); e.pack()
>>> # Type 'foo' into the Entry, then highlight it
...
>>> e.selection_get()
'foo'

e.selection_get() will raise TclError if the widget you call it on has
nothing selected.

>  >>> g.selection_get(selection='CLIPBOARD')

I didn't know about this, though..

-- 
John.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: return None

2005-07-24 Thread Repton
geon wrote:
> Ximo wrote:
> > Can I do a function which don't return anything?
> Nothing is None, or isnt?

A woodman was carrying a sack full of chopped wood on his back. His
sack was heavy and filled beyond its limit. The man, bent under his
bulky burden, was struggling not to drop any of the wood pieces as he
walked. However, the poor man couldn't avoid tripping over a stone on
the road and half of his load fell out of their precarious pile.
Another man happened to be passing by and saw the mishap.

`If I load those fallen pieces of wood back into your back sack, what
would you give me?' he asked.

`Nothing.' said the man carrying the wood.

`That's acceptable.' agreed the other man. He collected all the chopped
wood scattered on the road and crammed them back into the sack of the
woodman. When done, he asked for his payment. The woodman was baffled.

`I told you, I would give you nothing.' he said.

`Yes. And that's what I want. Nothing.' said the other, `Give me my
nothing!'

After some quarrel, the two men decided to let the qadi solve their
problem. Nasreddin Hodja was on duty at the time. He listened to both
men earnestly. Then he addressed the man who was expecting his payment
of nothing.

`My dear fellow, could you please lift the far right corner of that rug
on the floor and check what is underneath?' The man did as he was told
and looked under the rug.

`What do you see?' asked the Hodja.

`Nothing.' said the man.

'Well, there's your payment.' said the Hodja. 'Take it and go!'

-- 
John.

-- 
http://mail.python.org/mailman/listinfo/python-list


Searching through a list of tuples

2005-07-11 Thread Repton
I often find myself storing data in a list of tuples, and I want to ask
questions like "what is the index of the first tuple whose 3rd element
is x", or "give me the first tuple whose 2nd element is y".

I know I can do [elem for elem in lst if elem[3] == x][0] or (elem for
elem in lst if elem[2] == y).next() but it feels kinda ugly; is there a
better way?

(something like lst.index(x, key=..) or lst.find(y, key=..) would be
nice)

-- 
John.

-- 
http://mail.python.org/mailman/listinfo/python-list