20_组件OptionMenu

OptionMenu

选择菜单
import tkinter as tk

window = tk.Tk()
window.title('hello thinter')
height = window.winfo_screenheight()
width = window.winfo_screenwidth()
window.geometry('400x300+%d+%d' % ((width - 400) / 2, (height - 300) / 2))

variable = tk.StringVar()
variable.set("one")
list1 = ["青菜", "白菜", "菠菜", "黄瓜"]
w = tk.OptionMenu(window, variable, *list1)
w.pack()

def get_text():
    print("点击调用", variable.get())

tk.Button(window, text="获取文本值", command=get_text).pack()

window.mainloop()

posted @ 2022-10-09 10:25  interesting5319  阅读(29)  评论(0)    收藏  举报