所以我的计算类正在使用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()
Run Code Online (Sandbox Code Playgroud) 所以我正在用 tkinter 在 python 中制作一个秒表,我有更新时间工作的循环,但我有它所以循环清除文本框,然后用新数字更新文本框。
虽然它不起作用,但由于某种原因它只是没有清除它,它只是不断地向框中添加数字。
这是我使用的代码,如果有人能够帮我看看这个,我会非常感谢它:)
import time
from tkinter import *
root = Tk()
root.title("StopWatch")
#textbox for the screen
screen = Text(root, height = 1, width = 20, bd=10)
screen.grid(row=0, column=0)
#Active variable
global stopwatch_active
stopwatch_active = False
stop_time = 0
stop_minutes = 0
#command for starting the stopwatch
def start_com():
stop_btn.config(state=NORMAL)
stopwatch_active = True
start_btn.config(state=DISABLED)
global stop_time
stop_time += 1
screen.insert(END, stop_time)
root.after(1000, start_com)
#button for starting the stopwatch
start_btn = Button(root, text = "Start", width = …Run Code Online (Sandbox Code Playgroud)