Python 当按下按钮时,如何开始闪烁我的文本标签?
我试图在tkinter中创建一个文本标签,当按下1个按钮时,该标签将开始闪烁。 为此,我在tkinter文档和google上的其他教程的帮助下进行了尝试,但最终未能成功创建逻辑,因为我是python新手,我发现处理事件对象没有什么困难。 这是我的密码Python 当按下按钮时,如何开始闪烁我的文本标签?,python,tkinter,Python,Tkinter,我试图在tkinter中创建一个文本标签,当按下1个按钮时,该标签将开始闪烁。 为此,我在tkinter文档和google上的其他教程的帮助下进行了尝试,但最终未能成功创建逻辑,因为我是python新手,我发现处理事件对象没有什么困难。 这是我的密码 import tkinter as Tk flash_delay = 500 # msec between colour change flash_colours = ('white', 'red') # Two colours to swap
import tkinter as Tk
flash_delay = 500 # msec between colour change
flash_colours = ('white', 'red') # Two colours to swap between
def flashColour(object, colour_index):
object.config(background = flash_colours[colour_index])
root.after(flash_delay, flashColour, object, 1 - colour_index)
root = Tk.Tk()
root.geometry("100x100")
root.label = Tk.Text(root, text="i can flash",
background = flash_colours[0])
root.label.pack()
#root.txt.insert(Tk.END,"hello")
root.button1=Tk.Button(root,text="1")
root.button1.pack()
root.button.place(x=10,y=40,command = lambda: flashColour(root.label, 0))
root.mainloop()
place不接受命令作为参数。您应该使用lambda将其传递给按钮小部件
嗨,阿德,欢迎来到这个网站。在收到原始问题的帮助后,请不要编辑您的问题以提出不同的问题。这使得你收到的答案不再有意义。不可能回答移动的目标!如果你还有其他问题,你应该单独问。问几个相关的问题没有问题。您甚至可以从后面的问题链接到前面的问题,如果这有助于提供上下文,尽管您不一定需要。@Blckknght,好的,我明白了
root.button=Tk.Button(root,text="1",command = lambda: flashColour(root.label, 0))
root.button.pack()
#root.button.place(x=10,y=40) # you should use either `pack` or `place` but not both