2 回答

TA貢獻1798條經驗 獲得超3個贊
? ? #Color Picker
colorlist = ["#ff0000", "#0000ff"]
#Button Function
def render():
? ? global color
? ? import random
? ? from tkinter import Text
? ? input = (TextBox.get("1.0",'end-1c')) #Takes input from the Text Box
? ? win2 = Toplevel()
? ? win2.attributes("-fullscreen", True)
? ? TextFull = Text(win2,
? ? ? ? font="Ubuntu 14",
? ? ? ? fg="white",
? ? ? ? bg="black")
? ? for i in range (len(colorlist)):
? ? ? ? TextFull.tag_configure(str(i), foreground=colorlist[i])
? ? # TextFull.insert(0.0,input) #Displays Input from first window to second window
? ? TextFull.pack(fill=BOTH, expand=True)
? ? for i in input:
? ? ? ? tempchoice =random.randint(0, len(colorlist)-1)
? ? ? ? TextFull.insert(END, i, str(tempchoice))
? ? TextFull.insert(END, '\n')
終于設法通過使用 tag_configure 獲得了想要的結果。不是隨機單詞,而是字母,我可以接受。

TA貢獻1890條經驗 獲得超9個贊
首先,您必須創建具有初始前景色的文本小部件。然后你需要在一個定時的事情中改變前景的顏色。您可以使用after()該方法:
def render():
def flash(): # <-- flash()
TextFull.config(fg=choice(["#ff0000", "#0000ff"])) # <-- update color
win.after(1000, flash) # <-- call flash again after 1 second
global color
from tkinter import Text
input = (TextBox.get("1.0",'end-1c')) #Takes input from the Text Box
win2 = Toplevel()
win2.attributes("-fullscreen", True)
TextFull = Text(win2, font="Ubuntu 14", fg='#0000ff', bg="black")
TextFull.insert(0.0,input) #Displays Input from first window to second window
TextFull.pack(fill=BOTH, expand=True)
flash() # call flash
添加回答
舉報