1 回答

TA貢獻(xiàn)1789條經(jīng)驗(yàn) 獲得超8個(gè)贊
下面的代碼應(yīng)該做你想做的。無(wú)需破壞標(biāo)簽,您只需使用 .configure() 方法重新配置相同的標(biāo)簽即可。我懷疑你真正想要的方法是 .pack_forget() 所以我也包含了它。我沒(méi)有運(yùn)行這段代碼,所以如果您有任何問(wèn)題,請(qǐng)發(fā)表評(píng)論,以便我進(jìn)行更正。
from tkinter import *
from pynput.keyboard import Key, Controller
import time
root = Tk()
messages = 0
label = Label(root) # create your widgets early
root.geometry('500x1400')
def startn():
global messages
global label
message = "Read the Channel"
spam = int(input('How many sentences will you send?'))
label.pack() # only need to pack it once
for num in range(0, int((spam))):
messages = int(messages + 1)
label.configure(text= messages) # you should configure instead of making new label
def stopn():
label.pack_forget() # the label reference still exists, but it is no longer packed. You can destroy the label, but I just leave it for the garbage collector.
startn()
root.after(10000, stopn) # will run stopn callback after 10 seconds
root.mainloop() # in my opinion should always be at the end.
添加回答
舉報(bào)