Python Forum
[Tkinter] Get the last entry in my text widget
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Get the last entry in my text widget
#4
Thank you very much! I strained my brain making this work! Getting the penultimate line was tricky.

Obviously, your code is much better than mine! I don't know about float.

Just out of interest, this is what I did (the extra output is so I can see what is happening, I'll block that later):

def retrieve_input():        
        pos = text_area.index("end-1c")
        lineNum = pos.split('.')        
        line = int(lineNum[0]) - 1
        #echoMessage(str(line))
        pos2 = str(line) + '.0'
        answer = text_area.get(pos2, 'end-1c')        
        echoMessage('answer is ' + answer)
        echoMessage('pos is ' + pos)
        echoMessage('pos2 is ' + pos2)
        echoMessage('line number echoed was ' + str(line))
        return pos2;
Still using the window you made, I added a button 'Submit answer'

My little 'makehtmltable.py' asks me if I want to continue. It needs a 'y' to carry on. Now I can give it a y. This is the output in the text widget

Quote:Enter y to continue, enter nothing to stop.
y
answer is y

Thanks again for your help!
Reply


Messages In This Thread
RE: Get the last entry in my text widget - by Pedroski55 - Jul-13-2020, 10:34 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  ValueError: could not convert string to float: '' fron Entry Widget russellm44 5 797 Mar-06-2024, 08:42 PM
Last Post: russellm44
  [Tkinter] entry widget DPaul 5 1,585 Jul-28-2023, 02:31 PM
Last Post: deanhystad
  [Tkinter] The Text in the Label widget Tkinter cuts off the Long text in the view malmustafa 4 5,041 Jun-26-2022, 06:26 PM
Last Post: menator01
  Tkinter Exit Code based on Entry Widget Nu2Python 6 3,056 Oct-21-2021, 03:01 PM
Last Post: Nu2Python
  [Tkinter] Text widget inert mode on and off rfresh737 5 3,943 Apr-19-2021, 02:18 PM
Last Post: joe_momma
  Line numbers in Text widget rfresh737 3 5,494 Apr-15-2021, 12:30 PM
Last Post: rfresh737
  tkinter text widget word wrap position chrisdb 6 7,634 Mar-18-2021, 03:55 PM
Last Post: chrisdb
  method to add entries in multi columns entry frames in self widget sudeshna24 2 2,296 Feb-19-2021, 05:24 PM
Last Post: BashBedlam
  Entry Widget issue PA3040 16 6,954 Jan-20-2021, 02:21 PM
Last Post: pitterbrayn
  [Tkinter] password with Entry widget TAREKYANGUI 9 6,074 Sep-24-2020, 05:27 PM
Last Post: TAREKYANGUI

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020