check3.select() check3.grid(column=2, row=0, sticky=W) #进入消息循环 myWindow.mainloop() 实例2:绑定响应函数,代码如下: from tkinter import* def callCheckbutton(): #改变v的值,即改变Checkbutton的显示值 v.set('check CheckButton') #初始化Tk() myWindow = Tk() #设置标题 myWindow.title('...
selectborderwidth:指定当某个项目被选中的时候边框的宽度,默认是由 selectbackground 指定的颜色填充,没有边框, 如果设置了此选项,Listbox 的每一项会相应变大,被选中项为 RAISED 样式 selectforeground:指定当某个项目被选中的时候文本颜色, 默认值由系统指定 selectmode: 决定选择的模式,四种不同的选择模式:SINGLE...
from tkinterimport*importtkinter.messagebox#创建一个主窗口root=Tk()# 创建 宽400高250的窗口 x是小写的英文字符root.geometry('400x250')defprint_choice():print(listbox.curselection())# 创建一个列表框listbox=Listbox(root)listbox.pack()# 插入值listbox.insert(END,"a list entry")foritemin["one...
)root.title('Listbox 列表框演示')langs = ['Java', 'C#', 'C', 'C++', 'Python','Go', 'JavaScript', 'PHP', 'Swift']var = tk.StringVar()var.set(langs)listbox = tk.Listbox( root, listvariable=var, height=6, width=20, selectmode=tk.EXTENDED)listbox.pack(expand=...
label_select_display = Label(root) btn_get_select = Button(root, text='获取数据', command=get_select_item) label_select_display.pack() btn_get_select.pack() 显示效果如下: 3、设置为多选,并获取选中项 为ListBox 设置属性selectmode=MULTIPLE即可支持多选。
#将 selectmode 设置为多选模式,并为Listbox控件添加滚动条 listbox1=Listbox(win,selectmode=MULTIPLE,height=5,yscrollcommand=s.set) # i 表示索引值,item 表示值,根据索引值的位置依次插入 fori,iteminenumerate(range(1,50)): listbox1.insert(i,item) ...
root=tk.Tk()root.title("To-Do List Application")# 设置主窗口大小 root.geometry("400x400") 步骤3:创建任务列表 创建一个任务列表框,用于显示用户的任务列表: 代码语言:javascript 代码运行次数:0 运行 AI代码解释 task_listbox=tk.Listbox(root,selectmode=tk.SINGLE)task_listbox.pack(pady=10)# 添...
Listbox控件特有属性 属性说明listvariable1.指向一个 StringVar 类型的变量,该变量存放 Listbox 中所有的项目 2.在 StringVar 类型的变量中,用空格分隔每个项目,例如 var.set(“c c++ java python”)selectbackground指定当某个项目被选中的时候背景颜色,默认值由系统指定selectborderwidth1.指定当某个项目被选中的...
listbox1 = tk.Listbox(root,selectmode = 'multiple')#selectmode设置选择模式,有四种选择single(单选),browse(单选,但拖动鼠标或方向键可以改变选项),multiple(多选),extended(多选,但需同时按住shift和ctrl键或拖动鼠标实现) items = [('apple',0),('bag',1),('cat',2),('dog',3),('apple',0),...
combobox = ttk.Combobox(window, values=list) combobox.bind('<<ComboboxSelected>>', on_select...