如何在 Python 中從標籤中刪除文字?
Tkinter 是一個用於建立和開發基於 GUI 的應用程式的 Python 庫。在本文中,我們將學習如何從標籤中刪除文字,該標籤中有一些文字。
要從標籤中刪除文字,我們將建立一個關聯的按鈕,該按鈕將充當該標籤的觸發器。
示例
#import Tkinter Library
from tkinter import *
#Create an instance of tkinter frame
win= Tk()
#Define the size and geometry of the frame
win.geometry("700x400")
#Create a function for the Button Comman
def remove_text():
text.config(text=" ")
#Create a text Label
text= Label(win, text= "www.tutorialspoint.com", font= ("Poppins", 30))
text.pack(pady=20)
#Create a Button
my_button= Button(win, text= "Remove Text", command= remove_text)
my_button.pack(pady=10)
win.mainloop()輸出
執行上述程式碼將建立一個按鈕,可用於從標籤中刪除文字。

現在,單擊“移除文字”按鈕。它將從標籤中刪除文字,我們將獲得以下螢幕。

廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP