我創(chuàng)建了一個(gè)聊天應(yīng)用程序,在其中我使用 ListBox 來顯示聊天記錄。它看起來不錯(cuò),直到我進(jìn)入一個(gè)超出屏幕的長刺。有沒有辦法打破字符串并顯示在新行或任何其他方式來顯示完整的字符串。我是 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()
添加回答
舉報(bào)
0/150
提交
取消