一、代碼示例
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("Menu菜單參數說明")
# 設置窗口初始位置在屏幕居中
window.geometry("%sx%s+%s+%s" % (winWidth, winHeight, x, y))
# 設置窗口圖標
window.iconbitmap("./image/icon.ico")
# 設置窗口寬高固定
window.resizable(0, 0)
var = tk.StringVar()
var.set("請選擇")
tk.OptionMenu(window, var, "one", "two", "three").pack()
def getValue():
print(var.get())
tk.Button(window, text="get value", width=30, pady=5, command=getValue).pack()
window.mainloop()
二、效果圖

