python tkinter 文本框_如何在Tkinter中更新此文本框的文本?

所以我在python中用tkinter制作了一个秒表,我有一个更新工作时间的循环,但是我有它,循环会清除文本框,然后用新的数字更新文本框。在

虽然它不起作用,但由于某些原因它没有清除它,它只是不断地向框中添加数字。在

下面是我使用过的代码,如果有人能帮我看看这个,我会非常感激的:)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 = 10, bd = 5, command = start_com)

start_btn.grid(row=1, column=0, sticky=W)

#button for stopping the stopwatch

stop_btn = Button(root, text = "Stop", width = 10, bd = 5)

stop_btn.grid(row=1, column=0, sticky=E)

stop_btn.config(state=DISABLED)

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值