|
发表于 2021-5-8 10:51:47
|
显示全部楼层
1. def 要写在前面,组件前面
2. 触发函数,通常不用return,而是用传递函数或直接在内部处理,如使用Label显示
参考:
- root = Tk()
- root.geometry("500x400")
- frame_prehouse = ttk.Frame(root, )
- frame_prehouse.grid(row=0, column=0)
- # 设置“朝向”列表框
- def getorient(event):
- lb = Label(frame_prehouse, text=list_orient.get())
- lb.grid(row=3, column=1)
- # print(list_orient.get())
- # label_orient = ttk.Label(frame_prehouse,text="朝向:",font=("宋体",15))
- # label_orient.grid(row=2,columnspan=2,sticky=W,padx=160,pady=20)
- Orient = StringVar()
- list_orient = ttk.Combobox(frame_prehouse, textvariable=Orient, state='readonly', width=12)
- list_orient["value"] = ( '东', '东北', '东南', '北', '南', '西', '西北', '西南')
- list_orient.grid(row=2,columnspan=2,sticky=E)
- list_orient.current(0)
- list_orient.bind("<<ComboboxSelected>>", getorient)
- root.mainloop()
复制代码 |
|