i'm trying to implement my own edit menu using Tkinter,

my cut and copy methods,... seems to work fine but I'm having allot of trouble getting my paste method to work. will someone please help?

(((its kinda ugly i know, but i'm still new to programming and i'm more focused on getting it
to work right. later I'll go back and really clean up my code and oop practice. )))


app
app

are both entry widgets

app[ # ]
app[ # ]
app[ # ]
are lists of entry widgets

def _copy(self):
app=self.app

if app.select_present():
if app.focus_get():
app.clipboard_clear()
app.clipboard_append( app.selection_get() )


elif app.select_present():
if app.focus_get():
app.clipboard_clear()
app.clipboard_append( app.selection_get() )

else:
i = 0
for i in range(200):
app.clipboard_clear()
app.clipboard_clear()
app.clipboard_clear()

if app.select_present():
if app.focus_get():
app.clipboard_append(
app.selection_get() )

elif app.select_present():
if app.focus_get():
app.clipboard_append(
app.selection_get() )

elif app.select_present():
if app.focus_get():
app.clipboard_append(
app.selection_get() )


#####################################################################################
def _cut(self):
app=self.app

x=0
if app.select_present():
if app.focus_get():
app.clipboard_clear()
app.clipboard_append( app.selection_get() )
app.delete(SEL_FIRST,SEL_LAST)

elif app.select_present():
if app.focus_get():
app.clipboard_clear()
app.clipboard_append( app.selection_get() )
app.delete(SEL_FIRST,SEL_LAST)

else:
i = 0
for i in range(200):
app.clipboard_clear()
app.clipboard_clear()
app.clipboard_clear()

if app.select_present():
if app.focus_get():
app.clipboard_append(
app.selection_get() )
app.delete(SEL_FIRST,SEL_LAST)

elif app.select_present():
if app.focus_get():
app.clipboard_append(
app.selection_get() )
app.delete(SEL_FIRST,SEL_LAST)

elif app.select_present():
if app.focus_get():
app.clipboard_append(
app.selection_get() )
app.delete(SEL_FIRST,SEL_LAST)

##########################################################
def _paste(self):
if app.focus_get():
app.insert(INSERT, app.clipboard_get())

if app.focus_get():
app.insert(INSERT, app.clipboard_get())

...
...
...

<<<< this _paste method doesn't work, it always sets the focus to app
no mater where i paste at. How do I query where the insertion point is?

please someone help me. I've been going through Tkinter tutorials for over a week now, but i can not find a solution and i feel like its one of those really simple things that just keeps aluding me.

thanks.

Wrap your code in code tags:
[code=python] # Code here

[/code]

please elaborate,

the snippet above looks like <html> ... I'm useing python's IDLE

please leave an example :)

he was saying if you expect us to look at your code, put that before and after your code in your post. so that we can see syntax highlighting and what not.

he was saying if you expect us to look at your code, put that before and after your code in your post. so that we can see syntax highlighting and what not.

Yes, this is for the forum members' sake. This way your code doesn't lose indentation and become unreadable to us. It also saves space, and turns on syntax highlighting.

My suggestion would be to look at focus_displayof() instead of focus_get()

thank u to all

i'm still learning how everything works, and i'm still very much a newbe,..

I tried this:

w= app['info']['name'].displayof()
      w.insert(INSERT, w.selection_get() )

and got the following error:

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Python25\lib\lib-tk\Tkinter.py", line 1403, in __call__
    return self.func(*args)
  File "C:\Python25\prg\bs1.py", line 258, in _paste
    w= app['info']['name'].displayof()
AttributeError: Entry instance has no attribute 'displayof'

I appreciate all your patience and help,... i really am stuck,... I am self taught and also the only person in my life and family who has any interest in programming.. so hearing from you all was a real ray of hope 4 me :$

take the following code as an example:

from Tkinter import *

root = Tk()

def test():
	if (root.focus_displayof()==entry1):
		print 'hello'
	
entry1 = Entry(root)
entry2 = Entry(root)
button = Button(text='go', command=test)

entry1.pack()
entry2.pack()
button.pack()
root.mainloop()

This will create a form with two entry widgets and a button.

When the button is pressed it executes test(). If entry1 had the focus when I pressed the button it will print 'hello', otherwise... nothing.

also, for your purposes, since it looks like you would like to be able to paste in several different places I would do something like:

try:
	root.focus_displayof().insert(INSERT, root.focus_displayof().clipboard_get())
except:
	pass

that way, whichever widget has focus will recieve the paste. Unless it isn't capable of being pasted to, in which case it fails silently

thank u to all

i'm still learning how everything works, and i'm still very much a newbe,..

If you feel annoyed by Tkinter, try others also!
I found myself in love with wxpython. Some have fallen in hands of pyQt, PyGTK etc. I mean when you start learning try as amny available as you can and then choose among them. Don't underestimate Tkinter, I don't mean it is uselless, No! It is great, but I mean as I said you may fall in hands of one of those

Just MHO
Steve

I got it :) :) :)

thank you everyone

i'll mark this one as solved,.. and then I got to get ready 4 work

happy holloween everyone

This question has already been answered. Start a new discussion instead.