標題:
圖形介面 (五) - place排版練習
[打印本頁]
作者:
tonyh
時間:
2023-7-13 16:36
標題:
圖形介面 (五) - place排版練習
import tkinter as tk
win=tk.Tk()
win.title("主視窗")
win.geometry("500x500")
win.resizable(1,1)
lb=tk.Label(win,bg="#FFFF77",fg="red",text="這是絕對位置,下面是相對位置。",font=("微軟正黑體",16)).place(x=50, y=10) #anchor的預設值為nw
lb=tk.Label(win,bg="blue").place(relx=0.5, rely=0.5, relwidth=0.7, relheight=0.7, anchor="center")
lb=tk.Label(win,bg="yellow").place(relx=0.5, rely=0.5, relwidth=0.5, relheight=0.5, anchor="center")
lb=tk.Label(win,bg="red").place(relx=0.5, rely=0.5, relwidth=0.3, relheight=0.3, anchor="center")
lb=tk.Label(win,bg="green").place(relx=0.5, rely=0.5, relwidth=0.1, relheight=0.1, anchor="center")
win.mainloop()
複製代碼
屬性 說明
-----------------------------------------------------------------
relx 設定元件橫向相對位置,參數值在0與1之間
rely 設定元件縱向相對位置,參數值在0與1之間
relwidth 設定元件的相對寬度,參數值在0與1之間
relheight 設定元件的相對高度,參數值在0與1之間
anchor 設定元件位置基準點,有:center、n、s、w、e、nw、nw、sw、se
作者:
李沛昂
時間:
2023-7-13 16:55
import tkinter as tk
win=tk.Tk()
win.title("主視窗")
win.geometry("500x500")
win.resizable(1,1)
lb=tk.Label(win,bg="yellow",fg="red",text="這是絕對位置,下面是相對位置",font=("微軟正黑體",16)).place(x=50,y=10)
lb=tk.Label(win,bg="blue").place(relx=0.5,rely=0.5,relwidth=0.7,relheight=0.7,anchor="center")
lb=tk.Label(win,bg="green").place(relx=0.5,rely=0.5,relwidth=0.5,relheight=0.5,anchor="center")
lb=tk.Label(win,bg="yellow").place(relx=0.5,rely=0.5,relwidth=0.3,relheight=0.3,anchor="center")
lb=tk.Label(win,bg="red").place(relx=0.5,rely=0.5,relwidth=0.1,relheight=0.1,anchor="center")
win.mainloop()
複製代碼
作者:
王捷恩
時間:
2023-7-13 16:57
import tkinter as tk
win=tk.Tk()
win.title("主視窗")
win.geometry("500x500")
win.resizable(1,1)
lb=tk.Label(win,bg="blue").place(relx=0.5, rely=0.5, relwidth=0.7, relheight=0.7, anchor="center")
lb=tk.Label(win,bg="yellow").place(relx=0.5, rely=0.5, relwidth=0.5, relheight=0.5, anchor="center")
lb=tk.Label(win,bg="red").place(relx=0.5, rely=0.5, relwidth=0.3, relheight=0.3, anchor="center")
lb=tk.Label(win,bg="green").place(relx=0.5, rely=0.5, relwidth=0.1, relheight=0.1, anchor="center")
win.mainloop()
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2