tkinter将combobox控件的内容添加到entry控件中

import tkinter as tk
from tkinter import ttk

##### create the root window
root = tk.Tk()
root.title('示范')
root.resizable(False, False)
root.geometry('500x390+630+420')# (宽度x高度)+(x轴+y轴)

宽度=14
高度=25
左右內距=8
上下內距=5
左右间距=5
上下间距=5

#####combobox
lb_人员选择 = tk.Label(root,width =宽度,padx=左右间距,pady=上下间距,text="人员选择")
## Combobox(人员) creation
人员选择text = tk.StringVar()
人员选择 = ttk.Combobox(root,width = 宽度+2,height=高度, textvariable=人员选择text)
人员选择['values'] = ['小余','小华','小泽','小文']

##### entry
## entry label creation
lb_人员 = tk.Label(root,width =宽度,padx=左右间距,pady=上下间距,text="人 员")
人员text = tk.StringVar()
人员=ttk.Entry(root,width = 宽度+4)

####控件显示
lb_人员选择.grid(column=0,row=0, sticky="e")
人员选择.grid(column=1,row=0,padx=左右间距, sticky="w")
lb_人员.grid(column=0,row=1, sticky="e")
人员.grid(column=1,row=1,padx=左右间距, sticky="w")

def ajouter():
    人员.insert(tk.END, 人员选择.get()+"、")
    
#buton
buton=tk.Button(root,text='人员添加',fg='black',command=ajouter)
buton.place(x=256,y=35,height=22)

##### run the application
root.mainloop()

启发来源:https://stackoverflow.com/questions/69508584/how-get-values-from-combobox-to-write-into-textbox

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Allan_lam

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值