spi*_*paz 7 python string list python-3.x python-3.5
如何让字符串输出列表?(可能很简单,我知道)
我查看了所有的谷歌,没有任何解决方案工作.
我的代码:(有点解释)
import Pmw
from tkinter import *
root = Tk()
console = Pmw.ScrolledText(...some arguments...)
console.pack(...some arguments...)
console.settext(os.listdir("."))
root.mainloop()
Run Code Online (Sandbox Code Playgroud)
输出: file1.txt file2.txt file3.txt
在Pmw.ScrolledText框中.
我需要做什么才能使输出看起来如下所示?
file1.txt
file2.txt
file3.txt
Run Code Online (Sandbox Code Playgroud)
谢谢你.
使用换行符连接list
返回的项目:os.listdir()
filenames = os.listdir('.')
text = '\n'.join(filenames)
console.settext(text)
Run Code Online (Sandbox Code Playgroud)