首页 > 解决方案 > 如何使用 Tkinter 为文本框提供寄宿生。我尝试将 bg 作为一些值,但仍然无法看到寄宿生出现

问题描述

#Creating GUI with tkinter
import tkinter as tk
from tkinter import *

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

    if msg != '':
        ChatLog.config(state=NORMAL)
        ChatLog.insert(END, "You: " + msg + '\n\n')
        ChatLog.config( font=("Verdana", 15 ,'bold'),fg='green')

        res = chatbot_response(msg)
        ChatLog.insert(END, "MyBot:: " + res + '\n\n')

        ChatLog.config(state=DISABLED)
        ChatLog.yview(END)

base = Tk()
base.title("Hello")
base.geometry("400x500")
base.resizable(width=False, height=False)

#Create Chat window
ChatLog = Text(base, bg="#CCD1D1", height="8", width="50", font="Arial")

ChatLog.config(state=DISABLED)

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

#Create Button to send message
SendButton = Button(base, font=("Verdana",15,'bold'), text="Enter", width="12", height=10,
                    bd=10, bg='green', fg='#58D68D',
                    command= send )

#Create the box to enter message
EntryBox = Text(base, bg="#CCD1D1",width="29", height="5", font="Arial")

#Place all components on the screen
scrollbar.place(x=376,y=6, height=386)
ChatLog.place(x=6,y=6, height=386, width=370)
EntryBox.place(x=128, y=401, height=90, width=265)
SendButton.place(x=6, y=401, height=90)

base.mainloop()

如何将边界添加到输入文本空间?

我试过给 bg=4 或 bg=5 但仍然看不到寄宿生的出现。

如何解决此问题以及如何在 Enter 按钮上添加一些颜色?

标签: tkintertkinter-canvastkinter-layout

解决方案


bg用于背景颜色,而不是边框​​。您需要使用borderwidth(or bd) 和/或relief选项。


推荐阅读