如何獲取 Tkinter 標籤文字?
Tkinter 標籤用於在視窗上建立和顯示文字或影像。它有幾個元件和函式,可用於自定義標籤資訊,例如字型、填充、寬度、高度等。為了獲取視窗上的標籤文字,我們可以編寫必須在視窗上顯示的文字的值。
示例
#Import the required library from tkinter import * #Create an instance of tkinter frame win= Tk() #Define the geometry of the window win.geometry("600x250") #Create a Label with Text my_text= Label(win, text= "This is a New Line Text", font=('Helvetica bold', 16)) my_text.pack(pady=15) #Print the label text print(my_text['text']) win.mainloop()
輸出
以上程式碼將顯示標籤“這是一個新行文字”,該標籤可以透過列印函式打印出來。
廣告