如何正確設定粘性按鈕屬性?
Tkinter 按鈕可以透過 Tkinter 中不同的可用屬性進行配置。我們可以新增一個粘性屬性,使其相對於它所在的視窗具有粘性。sticky 屬性允許小部件設定視窗中的相對位置。要使按鈕具有粘性,我們必須選擇方向或位置,例如 N、E、S、W、NE、NW、SE、SW 和 0。
示例
#Import the tkinter library
from tkinter import *
from tkinter import ttk
#Create an instance of tkiner frame
win= Tk()
#Define the geometry of the function
win.geometry("750x250")
#Create a button to close the window
btn1 = ttk.Button(win, text ="I am in Column 3")
btn1.grid(column=3)
btn2=ttk.Button(win, text="I am stuck to South West")
btn2.grid(sticky=SW)
btn3= ttk.Button(win, text="I am stuck to North west")
btn3.grid(sticky=N)
win.mainloop()輸出
以上程式碼將顯示一個包含一些粘性按鈕的視窗。

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