如何使文本对齐对齐到右
from tkinter import *
#from time import *
root=Tk()
#root.geometry('2000x800')
ABC=Frame(root,bg='#1f5629',bd=20, relief=RIDGE)
ABC.grid()
def sent():
v=e.get()
sent="You => " + v
txt.insert(END,"\n"+sent)
if v=='hai':
a="bot ==>"+'hello'
txt.insert(END,"\n"+a)
e.delete(0,END)
ABC1=Frame(root,bg='#1f5629',bd=20,)
ABC1.grid()
txt=Text(ABC,height=30,width=40, padx=10,pady=10)
txt.grid(column=0,row=0)
e=Entry(ABC,width=30)
e.grid(row=1,column=0)
b=Button(ABC1,text='sent', command=sent)
b.grid(row=1,column=0)
root.mainloop()发布于 2020-07-29 04:29:13
您可以使用tag_config()定义带有选项justify="right"的标记。
txt = Text(ABC, height=30, width=40, padx=10, pady=10)
txt.grid(column=0, row=0)
txt.tag_config("right", justify="right")然后将此标记分配到您希望它正确正确的行:
if v == 'hai':
a = "bot ==> "+'hello'
txt.insert(END, "\n"+a, "right") # apply the "right" tab effect 更新:如果您希望在两秒钟后回复bot,则为:
if v == 'hai':
root.after(2000, txt.insert, END, '\nbot ==> hello', 'right')https://stackoverflow.com/questions/63141170
复制相似问题