tkinter - 如何使用 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 按钮上添加一些颜色?
解决方案
bg
用于背景颜色,而不是边框。您需要使用borderwidth
(or bd
) 和/或relief
选项。
推荐阅读
- python - 运行本地 python DNS 服务器时出现 Keyerror
- java - 使用 java 流过滤器按属性名称过滤重复项
- powershell - 搜索并获取文件,但如果值传递 null 则忽略代码
- c# - 如何编写一个新的计算器来接受可变数量的参数
- java - 使用黄瓜 DataTable 更新表单
- curl - 如何告诉 Facebook 爬虫跟踪链接?
- python - 无法单击元素-Selenium python
- php - PHP:加载页面上弹出验证错误
- python-3.x - 由于列表分配导致的越界错误?
- android - Android:使用哪个 api 来记录所有来电和去电(因为在更新日志中 Android 阻止了通话记录)