如何在 Tkinter 中設定 Label 控制元件的高度/寬度?
Label 控制元件用於在應用程式中顯示文字和影像。標籤控制元件的大小取決於多種因素,如標籤文字的寬度、高度和字型大小。
高度和寬度定義了標籤控制元件如何在視窗中顯示。若要設定標籤控制元件的高度和寬度,我們應該用變數來宣告 Label 控制元件。使用變數例項化標籤控制元件允許使用者新增/編輯標籤控制元件的屬性。
示例
# Import the required libraries from tkinter import * # Create an instance of tkinter frame or window win=Tk() # Set the size of the window win.geometry("700x350") # Add a Label widget label=Label(win, text="How to set the height/width " "of a Label widget in Tkinter?", font=('Times 14'), width=60, height=15) label.pack() win.mainloop()
輸出
執行上面的程式碼將顯示一個視窗,其中包含一個在寬度和高度內的標籤控制元件。
<a href="/articles/index.php"> <button class="button button--neutral"> <svg xmlns="http://www.w3.org/2000/svg" width="10" height="16" viewBox="0 0 10 16" fill="none"><path d="M1.03117 8.48836C0.64065 8.09783 0.64065 7.46467 1.03117 7.07414L7.39514 0.710183C7.78566 0.319658 8.41883 0.319658 8.80935 0.710183C9.19987 1.10071 9.19987 1.73387 8.80935 2.1244L3.15249 7.78125L8.80935 13.4381C9.19987 13.8286 9.19987 14.4618 8.80935 14.8523C8.41882 15.2428 7.78566 15.2428 7.39513 14.8523L1.03117 8.48836ZM3.12109 8.78125L1.73828 8.78125L1.73828 6.78125L3.12109 6.78125L3.12109 8.78125Z" fill="black"></path></svg> 上一頁 </button> </a> <a href="https://tutorialspoint.tw/how-to-set-the-width-of-a-tkinter-entry-widget-in-pixels"> <button class="button ">下一頁 <svg xmlns="http://www.w3.org/2000/svg" width="10" height="16" viewBox="0 0 10 16" fill="none"><path d="M8.87117 8.48836C9.26169 8.09783 9.26169 7.46467 8.87117 7.07414L2.50721 0.710183C2.11668 0.319658 1.48352 0.319658 1.09299 0.710183C0.70247 1.10071 0.70247 1.73387 1.09299 2.1244L6.74985 7.78125L1.093 13.4381C0.702471 13.8286 0.702471 14.4618 1.093 14.8523C1.48352 15.2428 2.11668 15.2428 2.50721 14.8523L8.87117 8.48836ZM6.78125 8.78125L8.16406 8.78125L8.16406 6.78125L6.78125 6.78125L6.78125 8.78125Z" fill="white"></path></svg> </button> </a>
廣告