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
添加回答
举报