我创建了一个简单的聊天 GUI。当我输入大文本时,它会不情愿地进入(或换行)到一个新行

I have created a simple chatting GUI. When I enter a large text, it goes (or wraps) into a new line unwillingly

我正在尝试创建一个简单的聊天界面,当我输入大文本时,例如:

Hello there, how are you? I hope 
you are doing great

显示为:

Hello there, how are you? I h
ope you are doing great

ChatLogEntryBox 都有这个问题。你能帮我解决这个问题吗?

代码如下:

[from datetime import datetime
from tkinter import *

def send(event):
    msg = EntryBox.get("1.0", 'end-1c').strip()
    EntryBox.delete("0.0", END)

    if msg != '':
        ChatLog.config(state=NORMAL)
        ChatLog.insert(END, current_time + " You: " + msg + '\n\n')
        ChatLog.config(foreground="#750216", font=("Verdana", 12))


def send_by_button():
    msg = EntryBox.get("1.0", 'end-1c').strip()
    EntryBox.delete("0.0", END)

    if msg != '':
        ChatLog.config(state=NORMAL)
        ChatLog.insert(END, current_time + " You: " + msg + '\n\n')
        ChatLog.config(foreground="#750216", font=("Verdana", 12))



base = Tk()
base.title("Simple Chat")
base.geometry("400x500")
base.resizable(width=FALSE, height=FALSE)

now = datetime.now()
current_time = now.strftime("%H:%M")

# Create Chat window
ChatLog = Text(base, bd=0, height="8", width="50", font="Arial", )
ChatLog.config(state=DISABLED)

# Bind scrollbar to Chat window
scrollbar = Scrollbar(base, command=ChatLog.yview, cursor="double_arrow")
ChatLog\['yscrollcommand'\] = scrollbar.set

# Create Button to send message
SendButton = Button(base, font=("Verdana", 12, 'bold'), text="SEND", width="12", height=5,
                    bd=0, fg="#750216", bg="#fff5f5", command=send_by_button)

# Create the box to enter message
EntryBox = Text(base, bd=0, fg="#750216", bg="#fff5f5", highlightcolor="#750216", width="29", height="5", font="Arial")

# Place all components on the screen
scrollbar.place(x=376, y=6, height=406)
ChatLog.place(x=6, y=6, height=386, width=370)
EntryBox.place(x=6, y=421, height=70, width=265)
SendButton.place(x=275, y=421, height=70)


# Refresh GUI window every 0.1 seconds, mainly for the "SEND" button.
# If the entry box does not contain text --> 'Send' button is inactive, otherwise it's activated.

def update():
    if (EntryBox.get("1.0", 'end-1c').strip() == ''):
        SendButton\['state'\] = DISABLED
    elif EntryBox.get("1.0", 'end-1c').strip() != '':
        SendButton\['state'\] = ACTIVE
    base.after(100, update)


base.bind('<Return>', send)
update()

base.mainloop()

我附上一张图片来澄清我的问题:

创建ChatLogEntryBox时需要添加wrap="word":

ChatLog = Text(base, bd=0, height="8", width="50", font="Arial", wrap="word")
...
EntryBox = Text(base, bd=0, fg="#750216", bg="#fff5f5", highlightcolor="#750216",
                width="29", height="5", font="Arial", wrap="word")