from tkinter import *
root=Tk()
root.title('search')
root.geometry('600x600')
root.resizable(False,False)
# Label(root,text='金额').pack()
# entry1=Entry(root).pack()
# Label(root,text='时间').pack()
# var=IntVar()
lb=Listbox(root,height=4,width=4)
list=[1,2,3,4]
for item in list:
lb.insert(END,item)
# Label(root,text='最终').pack()
# entry2=Text(root).pack()
var=StringVar()
var.set('look here!')
label=Label(root,textvariable=var).pack()
#定义的函数在()内需添加event,要不会报错显示:search函数为给定赋值位置,但有一个值要赋予。
def search(event):
var.set(lb.get(lb.curselection()))
lb.bind('<ButtonRelease-1>',search)
lb.pack()Button的回调函数是command,Listbox的回调函数是lb.bind。
listbox中获取值
最新推荐文章于 2023-06-16 15:01:21 发布
2110

被折叠的 条评论
为什么被折叠?



