亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何刪除標簽 Python

如何刪除標簽 Python

弒天下 2023-04-18 15:32:49
我的問題是我想要一個跟蹤器來跟蹤一個句子發送了多少次以及我何時運行:from tkinter import *from pynput.keyboard import Key, Controllerimport timeroot = Tk()messages = 0root.geometry('500x1400')def startn():    global messages    global label    message = "Read the Channel"    spam = int(input('How many sentences will you send?'))    for num in range(0, int((spam))):        messages = int(messages + 1)        label = Label(root, text= messages)        label.pack()    root.mainloop()                                startn()每當我在 label.pack() 之后添加 .destroy 時,它都不會顯示任何內容(順便說一句,spam = 5)在 label.pack() 之后輸出帶 .destroy 輸出不帶 .destroy
查看完整描述

1 回答

?
拉丁的傳說

TA貢獻1789條經驗 獲得超8個贊

下面的代碼應該做你想做的。無需破壞標簽,您只需使用 .configure() 方法重新配置相同的標簽即可。我懷疑你真正想要的方法是 .pack_forget() 所以我也包含了它。我沒有運行這段代碼,所以如果您有任何問題,請發表評論,以便我進行更正。


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.


查看完整回答
反對 回復 2023-04-18
  • 1 回答
  • 0 關注
  • 190 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號