Problem with Text widget Tkinter

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

Join Date: Jun 2008
Posts: 27
Reputation: TheOneElectroni is an unknown quantity at this point 
Solved Threads: 2
TheOneElectroni's Avatar
TheOneElectroni TheOneElectroni is offline Offline
Light Poster

Problem with Text widget Tkinter

 
0
  #1
Jul 8th, 2008
Hi everyone,

I have a problem to insert text into a text widget in Tkinter.
I want to be able that each time some text is inserted (by means of an action -not directly by the user-) that text is displayed into a new line.
However I can't figure out how to do this because everything I've tried showed me the same result: the new text is appended to the last character of the old text.
I've also tried to use the expression formatting, as shown in the following code excerpt, without success.
Can someone help me with this?

  1. i = "%s: %s" % (self.PSprod, self.PSv)
  2. self.InfoPoint.insert("%s lineend" % INSERT, i)

Thanks a lot,

Gab
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,297
Reputation: sneekula has a spectacular aura about sneekula has a spectacular aura about 
Solved Threads: 178
sneekula's Avatar
sneekula sneekula is offline Offline
Nearly a Posting Maven

Re: Problem with Text widget Tkinter

 
0
  #2
Jul 8th, 2008
Will something like this do?
  1. import Tkinter as tk
  2.  
  3. def set_text_newline(s):
  4. """start text s on a new line"""
  5. text1.insert(tk.INSERT, '\n' + s)
  6.  
  7. root = tk.Tk()
  8. # width=width characters, height=lines of text
  9. text1 = tk.Text(root, width=50, height=12, bg='yellow')
  10. text1.pack()
  11.  
  12. set_text_newline("line one")
  13. set_text_newline("line two")
  14. set_text_newline("line three")
  15.  
  16. root.mainloop()
No one died when Clinton lied.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 27
Reputation: TheOneElectroni is an unknown quantity at this point 
Solved Threads: 2
TheOneElectroni's Avatar
TheOneElectroni TheOneElectroni is offline Offline
Light Poster

Re: Problem with Text widget Tkinter

 
0
  #3
Jul 8th, 2008
Thanks a lot!
It now works perfectly like this

  1. self.InfoPoint.insert (INSERT, i)
  2. self.InfoPoint.insert(END, "\n")

Again, thank you so much
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 950 | Replies: 2
Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC