【发布时间】:2014-12-17 19:23:30
【问题描述】:
所以我的计算类正在用python制作一张圣诞卡,其中一个位将有一个带有消息的文本框,但我如何让背景从绿色和红色交替?
如果有人能够提供帮助,那就太棒了:)
from tkinter import *
root = Tk()
root.title("Xmas Message")
#command for the button
def test_com():
#removing the button
act_btn.grid_remove()
#adding the textbox for the message
msg_box = Text(root, height = 1, width = 30)
msg_box.grid(row=0, column=0)
#adding the message
msg_box.insert(END, "Happy Xmas")
#changing the background to green
msg_box.config(background="green")
#changing the background to red
msg_box.config(background="red")
root.after(250, test_com)
#button for activating the command
act_btn = Button(root, text = "1", command = test_com)
act_btn.grid(row=0, column=0)
root.mainloop()
【问题讨论】:
-
发布您目前拥有的一些代码,以便我们真正为您提供帮助。
-
你也是在 python 2.x 或 3.x 中做的吗?使用这两个标签可能会使试图帮助您的人感到困惑。
-
对不起,我没有意识到 python 2 已经进入标签,我正在使用 python 3,这是我到目前为止的代码
-
在我原来的帖子中,它现在在那里
标签: python python-3.x textbox tkinter