Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make a string output as a list in Pwm

How can I make a string output a list? (Probably very simple, I know)

I have looked through all of google, and NONE of the solutions worked.

My code: (it's a bit paraphrased)

import Pmw
from tkinter import *

root = Tk()

console = Pmw.ScrolledText(...some arguments...)
console.pack(...some arguments...)

console.settext(os.listdir("."))

root.mainloop()

Outputs: file1.txt file2.txt file3.txt in the Pmw.ScrolledText box.

What do I need to do to make the output look like the following?

file1.txt
file2.txt
file3.txt

My thanks to you.

like image 472
Jacob Birkett Avatar asked Oct 20 '15 23:10

Jacob Birkett


2 Answers

Join the items in the list returned by os.listdir() using a new-line character:

filenames = os.listdir('.')
text = '\n'.join(filenames)
console.settext(text)
like image 75
slezica Avatar answered Sep 28 '22 21:09

slezica


You can use \n (new line character). for example: print 'file1.txt\nfile2.txt\nfile3.txt'

You can find more information here - https://docs.python.org/2/tutorial/inputoutput.html

like image 34
Boaz Galil Avatar answered Sep 28 '22 21:09

Boaz Galil