python - 位图“颜色”未定义
问题描述
我的代码:
import tkinter as tk
win = tk.Tk()
txt = tk.Text(win, width = 50, height = 20)
txt.pack()
txt.insert('insert', 'Hello1\n')
txt.insert('insert', 'Hello2')
txt.tag_add('format1', '1.0', '1.5')
txt.tag_configure('format1', bg = 'blue')
win.mainloop()
错误:
上面的代码与下面的代码类似,因为我以它为例。
示例代码:
from Tkinter import *
def onclick():
pass
root = Tk()
text = Text(root)
text.insert(INSERT, 'Hello.....')
text.insert(END, 'Bye Bye.....')
text.pack()
text.tag_add('here', '1.0', '1.4')
text.tag_add('start', '1.8', '1.13')
text.tag_configure('here', background = 'yellow', foreground = 'blue')
text.tag_configure('start', background = 'black', foreground = 'green')
win.mainloop()
来源:https ://www.tutorialspoint.com/python/tk_text.htm
问题:
我的代码中的错误在哪里?就我而言,bg
选项会产生错误,因为如果我们改变它的值,比如说红色,我们会得到:
解决方案
推荐阅读
- python - 如何在 Python 的帮助下提高 Ping
- flutter - 创建两个相互独立的小部件
- php - 使用 PHP(Oracle 数据库)更新 BLOB 字段图像文件
- python - 如何通过从零开始构建的神经网络提高预测的准确性?
- json - 无法在 Windows 中使用 curl 发布 json 数据
- javascript - 在函数参数中分配变量如何工作?这样做的目的是什么?
- jquery - 使用 Ajax Jquery 时 DataTable 不刷新
- fable-r - 在 tidyverts 包中按键创建时间序列交叉验证切片
- java - 以下 switch 语句有什么问题?
- meshlab - 默认情况下,Meshlab 如何在导出网格中计算法线?