我正在学习新的python。我正在尝试设计一个聊天机器人。我已经添加了到目前为止所做的代码。我希望长篇文章中气泡之间的距离保持恒定。你能帮忙吗?很抱歉我的英语不好。
from tkinter import *
from datetime import datetime
import random
import re
from tkinter import messagebox
from tkinter.font import Font
import textwrap
root = Tk()
root.config(bg="lightblue")
root.geometry('410x600+400+100')
#ana ekran
canvas = Canvas(root, width=200, height=200,bg="white")
canvas.grid(row=0,column=0,columnspan=2)
canvas.place(x=10, y=10, width=390, height=530)
balon = []
class balon1:
def __init__(self,master,message=""):
self.master = master
self.frame = Frame(master,bg="light green")
self.i = self.master.create_window(30,490,window=self.frame, anchor="sw")
Label(self.frame,text=datetime.now().strftime("%d-%m-%Y %X"),font=("Helvetica", 7),bg="light green").grid(row=0,column=0,sticky="w",padx=5) #tarih saat
Label(self.frame, text=textwrap.fill(message, 35), font=("Helvetica", 9),bg="light green").grid(row=1,column=0,sticky="w",padx=5,pady=3)
root.update_idletasks()
self.master.create_polygon(self.draw_triangle(self.i), fill="light green", outline="light green")
def draw_triangle(self,widget):
x1, y1, x2, y2 = self.master.bbox(widget)
return x1, y2 - 10, x1 - 15, y2 + 10, x1, y2
def send_message():
if balon:
canvas.move(ALL, 0, -70)
a = balon1(canvas,message=entry.get())
balon.append(a)
#mesaj yazma alanı
entry = Entry(root,width=26, font=("Helvetica", 10))
entry.place(x=10, y=550, width=290, height=40)
#buton
buton = Button(root, width=10, height=2, relief='raised',state='active',command=send_message)
buton.config(text='GÖNDER', bg='lightblue', font='Verdana 8 bold')
buton.place(x=310, y=550)
root.mainloop()
答案 0 :(得分:0)
我认为最简单的方法是从创建气泡开始,然后获得气泡的高度。然后,将所有内容向上移动该数量再加上一个边距,然后将气泡移动到其所属的位置。
更简单的方法可能是简单地在当前气泡下添加新气泡,然后向上滚动所有内容以使其可见。