python tkinter entry长字符串靠右显示_Python tkinter Entry小部件显示条形字符而不是换行符...

我正在编写一个非常简单的Python Tkinter GUI来驱动命令行python脚本 .

我的GUI将在Windows主机上运行,我希望它显示脚本的多行纯文本输出,该输出作为包含 - 当然 - 换行符( \n 个字符)的字符串返回到GUI .

因此,我将一个Text小部件放入GUI中,当我的脚本(例如)返回以此子字符串开头的输出时:

RESULT STATUS: OK- Service is currently running\n\nDETAILS: ...

只要有 \n 换行符,显示的文本就会包含黑色竖条( | ) .

线被正确打破但是那些奇怪的条让我觉得 \n 换行符没有被正确解码,我不希望显示输出中的条 .

有关如何使Tkinter正确显示行结尾的任何想法?提前致谢 .

代码

这是我的GUI的工作流程:

我点击了一个调用callMe()回调函数的按钮

callMe()函数解析来自Entry小部件的参数,然后调用python命令行脚本

该脚本返回上述字符串,回调函数使用它来更新Text小部件的文本

这是代码:

#init the GUI elements and the Text widget

from Tkinter import *

root = Tk()

top = Frame(root)

outputFrame = Frame(top)

outputFrame.pack(side='top', padx=20, pady=20)

outputTextArea = Text(outputFrame, yscrollcommand=scrollbar.set, width=150, height=40)

outputTextArea.pack(side='left', expand=YES, fill='both')

#callback executed when the button is clicked

def callMe()

#get parameters

# .....

#command line execution script execution

process = subprocess.Popen(command_line, stdout=subprocess.PIPE, shell=True)

#get script output

matr = process.stdout.readlines()

#from a list of strings to a single string

output = "".join(matr)

#write output into the Text widget

outputTextArea.insert(0.0, output)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值