【问题标题】:Recolor specific words inside of a Tkinter Label重新着色 Tkinter 标签内的特定单词
【发布时间】:2021-08-14 11:38:30
【问题描述】:

我制作了一个 python 脚本来按特定单词查找一些歌词,当我显示结果时,我想为搜索到的单词重新着色。

我在一个按钮上有一个点击监听器,它调用相应的函数,名为bestMatch。结果是大字符串,这将是我的结果标签的文本。

import tkinter as tk

def clickMe():
    global window
    global results
    global name
    retValue = bestMatch(name.get())
    result = ''
    for i in retValue:
        result = result + enekeskonyv[int(i[0])] + '\n'
    for widget in resultFrame.winfo_children():
        widget.destroy()
    tk.Label(resultFrame, text= 'Result by- ' + name.get() + ': \n' + result).grid(padx=10, sticky=W)

最后一个标签将包含我的结果,我没有找到任何用于 tkinter 标签的重新着色方法。

【问题讨论】:

标签: python tkinter label tk


【解决方案1】:

您无法更改label 小部件中的一些文本,但您可以使用text 小部件来做到这一点:

How to change the color of certain words in the tkinter text widget?

【讨论】:

    猜你喜欢
    • 2014-03-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-08
    • 2019-05-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多