Targets?

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: May 2008
Posts: 42
Reputation: tondeuse34 is an unknown quantity at this point 
Solved Threads: 2
tondeuse34's Avatar
tondeuse34 tondeuse34 is offline Offline
Light Poster

Targets?

 
0
  #1
May 15th, 2008
Is there a function out their in python that you will declare a target i.e. a text box on another open window, and it would print text to that screen? Thanks
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 608
Reputation: jrcagle is on a distinguished road 
Solved Threads: 150
jrcagle jrcagle is offline Offline
Practically a Master Poster

Re: Targets?

 
0
  #2
May 15th, 2008
So you want a text box in one window, and what you type in the text box will also show up in another window?
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 42
Reputation: tondeuse34 is an unknown quantity at this point 
Solved Threads: 2
tondeuse34's Avatar
tondeuse34 tondeuse34 is offline Offline
Light Poster

Re: Targets?

 
0
  #3
May 15th, 2008
sort of, but for example if you had a open notepad it would print "Hello World!" onto that notepad
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 608
Reputation: jrcagle is on a distinguished road 
Solved Threads: 150
jrcagle jrcagle is offline Offline
Practically a Master Poster

Re: Targets?

 
0
  #4
May 16th, 2008
So two text boxes, and the text from one goes into the other?

(or do you mean MS Notepad? That would be quite a challenge).

Here's a small example:

  1. import Tkinter as tk
  2.  
  3. class MyFrame(tk.Frame):
  4.  
  5. def __init__(self, parent):
  6. tk.Frame.__init__(self, parent)
  7. self.text1 = tk.Text(self, width=40, height=10)
  8. self.text2 = tk.Text(self, width=40, height=10, state=tk.DISABLED)
  9. self.text1.grid()
  10. self.text2.grid()
  11.  
  12. self.text1.bind("<Any-KeyPress>", self.copytext)
  13.  
  14. def copytext(self, event):
  15. text = self.text1.get("0.0", tk.END)
  16. self.text2["state"]=tk.NORMAL
  17. self.text2.delete("0.0", tk.END)
  18. self.text2.insert("0.0", text)
  19. self.text2["state"]=tk.DISABLED
  20.  
  21. app = tk.Tk()
  22. app.frame = MyFrame(app)
  23. app.frame.grid()
  24. app.mainloop()

It's not perfect -- the second Text widget is one character behind the first because the <Any-KeyPress> event is processed prior to the key being inserted into the first Text.

But it gives a decent idea.

Jeff
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 42
Reputation: tondeuse34 is an unknown quantity at this point 
Solved Threads: 2
tondeuse34's Avatar
tondeuse34 tondeuse34 is offline Offline
Light Poster

Re: Targets?

 
0
  #5
May 16th, 2008
thanks for answering my question your code works perfect
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Python Forum


Views: 499 | Replies: 4
Thread Tools Search this Thread



Tag cloud for Python
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC