所以我抓住了一個網站上的事件鏈接,並將它們放入一個下拉菜單中進行選擇。我的菜單代碼:更改tk選項菜單中單個單詞的顏色?
import Tkinter as tk
from Tkinter import StringVar
selectMenu = tk.Tk()
# #-> this is what I have
# Followed by what you can use
#var = Vars()
#events = var.GetVars('Event')
events = " "
options = []
links = []
#forms = (driver.find_elements_by_class_name("with-cats")) #This is what I have
forms = ["Yolo ","Dad? Closed","Anotha One","Normies! Closed"] #This is so you can try it for yourself
for x in forms:
#info = x.text
info = x #Again, this is so you can try it for yourself
if events in info.lower():
links.append(x)
for link in range(0,len(links)):
#options.append(links[link].text)
options.append(links[link])
list(set(options))
selection = []
for link in range(0,len(options)):
selection.append(options[link])
select = StringVar(selectMenu)
select.set("--None Selected--")
menu = tk.OptionMenu(selectMenu, select, *(selection))
msg = "Which one would you like to attend?"
label = tk.Label(selectMenu, text=msg, font="Helvedica 14")
label.pack(side='top', pady=10)
menu.pack(side="top", pady=10)
selectMenu.attributes('-topmost', True)
selectMenu.mainloop()
所以此工程罰款和花花公子,但我想改善一下,以使其更明顯的事件是開放的。爲了澄清,發現一個事件被打開並放入菜單可能看起來像「這是一個很酷的事件」,但是一個被關閉的事件將被視爲「這是一個很酷的事件已關閉」。我的目標是能夠使前景變成紅色,不管是Closed還是包含Closed的字符串(如果有可能的話)(我不確定是否可能,因爲osx上的菜單和按鈕通常默認爲系統設置,也許有辦法解決這個問題?)。
Current: Desired:
請提供[最小,完整的,並且可驗證示例](https://stackoverflow.com/help/mcve)。這將使我們能夠協助你解決問題。沒有足夠的代碼來重現問題。沒有MCVE,它將不太可能獲得您正在尋找的答案。 –
對不起,我很困惑,想要製造什麼問題?你能澄清一下嗎? – Jake
問題是你想弄清楚如何改變一個單詞或包含該單詞的字符串的顏色,是否正確? –