【发布时间】:2017-07-04 10:41:47
【问题描述】:
这是我的代码:
from tkinter import *
root = Tk()
root.title("Punctured Convolution Encoder dan Viterbi Decoder")
root.geometry("1350x655+0+0")
frame_input = LabelFrame(root, text="Input")
frame_input.place(x=20, y=10, width=400, height=200)
# input#
lbl_in = Label(frame_input, text="Input", font=("Arial", 16))
lbl_in.place(x=10, y=20)
bin_in = Entry(frame_input, font=('Gill Sans MT', 16))
bin_in.place(x=130, y=20, width=240)
def klik_proses():
bin_in.selection_range(1,2)
bin_in.config(foreground="red")
bin_in.selection_range(4,5)
bin_in.config(foreground="red")
btn_proses = Button(frame_input, text="test", width=12, command=klik_proses)
btn_proses.place(x=140, y=100)
root.mainloop()
结果是当我按下按钮时,条目小部件中整个文本的颜色发生了变化。 如何更改条目小部件中某些文本的颜色?
例如:
我在输入框中输入123456789,然后我想更改数字2 和5 的文本颜色。
因此,有 2 个数字为红色,其他数字为黑色。
【问题讨论】:
-
Entry 小部件仅支持单一前景色。文本和画布小部件支持多种彩色文本。
标签: python-3.x tkinter widget foreground tkinter-entry