首页 > 解决方案 > 当我在 tkinter 中调用我为 bind 创建的函数时,我应该给出什么参数

问题描述

下面是一个问题的例子:

from  tkinter import ttk
from tkinter import *

root = Tk()

combobox1 = ttk.Combobox(root, values = ('Jan', 'Feb', 'August'))
combobox1.pack()

comb2 = ttk.Combobox(root, state=DISABLED)
comb2.pack()

def comb1_selected(*args):
    someword = "" 
    if combobox1.get() == 'Jan':
        someword = 'J'
        comb2.config(state='normal')
        comb2.config(values=someword)
    return someword

def use_comb1_selected():
    print(comb1_selected(*args))

use_comb1_selected() #What arguments should I give here??

combobox1.bind("<<ComboboxSelected>>", comb1_selected)

root.mainloop()

我无法弄清楚要为我创建的函数提供哪些参数尝试提供诸如“事件”之类的参数导致以下错误

    NameError: name 'event' is not defined

如果没有参数,该函数什么也不做,即使它应该打印为 'J'

请帮助我了解我需要做什么

标签: pythontkinterbind

解决方案


推荐阅读