为了账号安全,请及时绑定邮箱和手机立即绑定

如何在 tkinter python 中动态添加多行文本?

如何在 tkinter python 中动态添加多行文本?

暮色呼如 2021-09-01 19:30:07
我创建了一个聊天应用程序,在其中我使用 ListBox 来显示聊天记录。它看起来不错,直到我进入一个超出屏幕的长刺。有没有办法打破字符串并显示在新行或任何其他方式来显示完整的字符串。我是 Tkinter 的新手,我不知道有很多小部件可用。这是我的示例代码from tkinter import *class Actions:    def chatUpdate(chat):        chatlist.insert(Actions.chatLast,chat)        Actions.chatLast=Actions.chatLast+1        chatlist.pack( side=LEFT, fill=BOTH)        chatBox.config(command=chatlist.yview)def callUpdater():    txt=textBox.get()    text_text.set("")    Actions.chatUpdate(txt)root = Tk()root.title("Chat App")frame1 = Frame(root, bd=4)frame1.pack(side=TOP)frame2 = Frame(root, bd=4)frame2.pack(side=TOP)frame3 = Frame(root, bd=4)frame3.pack(side=TOP)# chat boxchatBox = Scrollbar(frame1)chatBox.pack(side=RIGHT, fill=Y)chatlist = Listbox(frame1, yscrollcommand = chatBox.set, width=50)Actions.chatLast=0Actions.chatUpdate("                        ")# text boxtextView = Label(frame2, text="Input: ")textView.pack(side=LEFT)text_text = StringVar()textBox = Entry(frame2, textvariable=text_text, bd=0, width=40, bg="pink")textBox.pack(side=RIGHT)# send buttonbutton = Button(frame3, text="Send", fg="black", command=callUpdater)button.pack(side=TOP)root.mainloop()
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 338 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信