1、參數說明python
width | 設置寬度 |
height | 設置高度 |
background(bg) | 設置背景顏色 默認值由系統指定 爲了防止更新,能夠將顏色值設置爲空字符串 |
borderwidth(bd) | 設置邊框寬度 |
menu | 設置該選項爲 Toplevel 窗口提供菜單欄 |
padx | 水平方向上的邊距 |
pady | 垂直方向上的邊距 |
relief | 指定邊框樣式,另外你還能夠設置 "sunken","raised","groove" 或 "ridge"注意,若是你要設置邊框樣式,記得設置 borderwidth 或 bd 選項不爲 0,才能看到邊框 |
2、代碼示例oop
import tkinter as tk window = tk.Tk() # 設置窗口大小 winWidth = 600 winHeight = 400 # 獲取屏幕分辨率 screenWidth = window.winfo_screenwidth() screenHeight = window.winfo_screenheight() x = int((screenWidth - winWidth) / 2) y = int((screenHeight - winHeight) / 2) # 設置主窗口標題 window.title("TopLevel參數說明") # 設置窗口初始位置在屏幕居中 window.geometry("%sx%s+%s+%s" % (winWidth, winHeight, x, y)) # 設置窗口圖標 window.iconbitmap("./image/icon.ico") # 設置窗口寬高固定 window.resizable(0, 0) def add(): # 建立頂級窗口 top_level = tk.Toplevel() top_level.title("新窗口") tk.Label(top_level, text="i am yang").pack() tk.Button(window, text="建立窗口", command=add).pack() window.mainloop()
3、效果圖spa