如何设置按钮的输出(命令= def()),作为组合框值的输入=

时间:2019-05-05 10:51:55

标签: python tkinter combobox

我正在尝试将其他输入设置为Combobox(values = output) 功能(已连接到Button(command = some_function)

from tkinter import ttk
from tkinter import filedialog
from tkinter import *

def select():
    global sel
    a = ['101','102','103','104','105']
    b = ['201','202','203','204','205']
    sel = []
    #label.configure(text = " Fleet" + fleet.get())
    choosed = fleet.curselection()
    for i in choosed:
        selection = fleet.get(i)
        print ("selected " + " " + selection)
        if selection == 'B':
            sel = b
        else: sel = a
    #print (sel)
    return sel

root =Tk()
fleet = Listbox(root, width = 10, height = 2)
fleet.insert(1, 'B')
fleet.insert(2, 'A')
fleet.grid(column = 1, row = 0)

label = ttk.Label(root, text = "Please choose the fleet")
label.grid (column = 0, row = 0)

button1 = ttk.Button(root, text = 'Select', command = select)
button1.grid(column = 0, row = 1)

a = ['101','102','103','104','105']
b = ['201','202','203','204','205']

combo_tool_num = ttk.Combobox(root, width = 10, values = sel)

我想将select()的输出sel设置为combo_tool_num values = sel的输入。
谢谢!

1 个答案:

答案 0 :(得分:0)

要在组合框中设置初始值,请使用“ set()” 使用语法为, combo_tool_num = ttk.Combobox(根,宽度= 10,值= sel) combo_tool_num.set('选择')