Jump to content

[TKINTER] How do print ttk.Text's text

WillLTT

im trying and have been trying to do this one simple thing.

 

Ive made a ttk.Text, im trying to extract what someone wrote in it.

I refuse to use ttk.Entry as it is not MULTILINE. Multiline was the whole purpose of using ttk.Text

 

im trying to get all the lines into a string list (array). i cannot manage this.

 

I cannot find any documentation on this.

im willing to use ttk.Entry if its multiline.. 

 

Example code of what i want to achieve:

String[] text = text_input
print(text[1]) //print line one of the textbox

also i know thats not how python lists work, but its for an example code only. 

 

HOW?! ive been thru the 3 first pages of google!

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, WillLTT said:

im trying and have been trying to do this one simple thing.

 

Ive made a ttk.Text, im trying to extract what someone wrote in it.

I refuse to use ttk.Entry as it is not MULTILINE. Multiline was the whole purpose of using ttk.Text

 

Example code of what i want to achieve:


String[] text = text_input
print(text[1]) //print line one of the textbox

HOW?! ive been thru the 3 first pages of google!

Does the 'print(text[1])' line work? Does replacing that '1' for a '2' work?

If so, can you write a for loop for this language?

"We're all in this together, might as well be friends" Tom, Toonami.

 

mini eLiXiVy: my open source 65% mechanical PCB, a build log, PCB anatomy and discussing open source licenses: https://linustechtips.com/topic/1366493-elixivy-a-65-mechanical-keyboard-build-log-pcb-anatomy-and-how-i-open-sourced-this-project/

 

mini_cardboard: a 4% keyboard build log and how keyboards workhttps://linustechtips.com/topic/1328547-mini_cardboard-a-4-keyboard-build-log-and-how-keyboards-work/

Link to comment
Share on other sites

Link to post
Share on other sites

5 minutes ago, minibois said:

Does the 'print(text[1])' line work? Does replacing that '1' for a '2' work?

If so, can you write a for loop for this language?

tkinter is a import in python, not a own language :) 'print(text[1])' will not work as i do not yet have a array list of the lines of ttk.Text, im trying to achieve that :)

Link to comment
Share on other sites

Link to post
Share on other sites

6 minutes ago, WillLTT said:

tkinter is a import in python, not a own language :) 'print(text[1])' will not work as i do not yet have a array list of the lines of ttk.Text, im trying to achieve that :)

This might work for you:

https://stackoverflow.com/questions/14676265/how-to-read-a-text-file-into-a-list-or-an-array-with-python

 

 

"We're all in this together, might as well be friends" Tom, Toonami.

 

mini eLiXiVy: my open source 65% mechanical PCB, a build log, PCB anatomy and discussing open source licenses: https://linustechtips.com/topic/1366493-elixivy-a-65-mechanical-keyboard-build-log-pcb-anatomy-and-how-i-open-sourced-this-project/

 

mini_cardboard: a 4% keyboard build log and how keyboards workhttps://linustechtips.com/topic/1328547-mini_cardboard-a-4-keyboard-build-log-and-how-keyboards-work/

Link to comment
Share on other sites

Link to post
Share on other sites

4 minutes ago, minibois said:

Im not reading a text file, im trying to read a python tkinter's Text property. what is the equivelent of a Rich text box, And put the lines of the Rich text box into a array list. thanks for helping :)

Link to comment
Share on other sites

Link to post
Share on other sites

2 minutes ago, WillLTT said:

Im not reading a text file, im trying to read a python tkinter's Text property. what is the equivelent of a Rich text box, And put the lines of the Rich text box into a array list. thanks for helping :)

If you print the .text property, does it have the next lines built in? If so, you can probably split the Text property on \n (that is probably the next line 'command') and then insert it into an array.

lines = text.split("\n")  

I am not sure how Python/Tkinter deals with have \n in a string.You might need to escape it using an @ at the beginning of the sentence.. But this is probably kind of what is needed.

24 minutes ago, WillLTT said:

String[] text = text_input
print(text[1]) //print line one of the textbox

 

Not sure how Python works with arrays, but most programming languages begin an array at 0. So text[1] would in fact be the second line

"We're all in this together, might as well be friends" Tom, Toonami.

 

mini eLiXiVy: my open source 65% mechanical PCB, a build log, PCB anatomy and discussing open source licenses: https://linustechtips.com/topic/1366493-elixivy-a-65-mechanical-keyboard-build-log-pcb-anatomy-and-how-i-open-sourced-this-project/

 

mini_cardboard: a 4% keyboard build log and how keyboards workhttps://linustechtips.com/topic/1328547-mini_cardboard-a-4-keyboard-build-log-and-how-keyboards-work/

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, minibois said:

If you print the .text property, does it have the next lines built in? If so, you can probably split the Text property on \n (that is probably the next line 'command') and then insert it into an array.


lines = text.split("\n")  

I am not sure how Python/Tkinter deals with have \n in a string.You might need to escape it using an @ at the beginning of the sentence.. But this is probably kind of what is needed.

Not sure how Python works with arrays, but most programming languages begin an array at 0. So text[1] would in fact be the second line

Arrary lists in python work like this: " list = ["one", "two", "three"] " remove the " tho. 

 

But first, i have to get the text out of the textbox

tkk.Text Reference i cannot find anything to extra from the textbox only insert. Got any ideas? 

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, WillLTT said:

Arrary lists in python work like this: " list = ["one", "two", "three"] " remove the " tho. 

 

But first, i have to get the text out of the textbox

tkk.Text Reference i cannot find anything to extra from the textbox only insert. Got any ideas? 

https://stackoverflow.com/questions/14824163/how-to-get-the-input-from-the-tkinter-text-box-widget

Seems like you can use a .get() method on the textbox + some parameters.

"We're all in this together, might as well be friends" Tom, Toonami.

 

mini eLiXiVy: my open source 65% mechanical PCB, a build log, PCB anatomy and discussing open source licenses: https://linustechtips.com/topic/1366493-elixivy-a-65-mechanical-keyboard-build-log-pcb-anatomy-and-how-i-open-sourced-this-project/

 

mini_cardboard: a 4% keyboard build log and how keyboards workhttps://linustechtips.com/topic/1328547-mini_cardboard-a-4-keyboard-build-log-and-how-keyboards-work/

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×