[英]appJar - ListBox/OptionBox widget call a function on select
I recently started playing with appJar python module and I got stuck using its widgets, namely ListBox http://appjar.info/pythonWidgets/#listbox and OptionBox http://appjar.info/pythonWidgets/#optionbox . 最近,我开始使用appJar python模块,并使用了其小部件,即ListBox http://appjar.info/pythonWidgets/#listbox和OptionBox http://appjar.info/pythonWidgets/#optionbox 。
I am not able to find out, how to call function when item in ListBox or OptionBox is selected. 我无法找出在选择ListBox或OptionBox中的项目时如何调用函数。 I found this syntax, but I cannot find where to define the function I want to call:
我找到了这种语法,但是找不到在哪里定义要调用的函数:
.selectListItem(title, item, callFunction=True)
.changeOptionBox(title, newOptions, index, callFunction=False)
This is the code, which I have so far. 这是我到目前为止所拥有的代码。 As you can see, I am able to print out selected values, but by calling method on button click.
如您所见,我可以打印出选定的值,但是可以通过单击按钮上的方法来调用。
from appJar import gui
def press(btn):
if btn == "Cancel":
app.stop()
elif btn == "Show":
list_select()
else:
print('not defined yet')
def list_select():
app.infoBox("Info", "You selected " + app.getOptionBox("optionbox") + "\nBrowsing " + app.getListBox("list")[0])
app = gui("Database Editor", "500x500")
app.addOptionBox("optionbox", ["a", "b", "c", "d"])
app.addListBox("list", ["one", "two", "three", "four"])
app.addButtons(["Show", "Cancel"], press)
app.go()
Is any of you aware, how can I print out these values directly on the select? 你们知道吗,我如何直接在选择项上打印出这些值?
I've figured it out! 我知道了! Indeed the ChangeFunction can be triggered through the Event function http://appjar.info/pythonEvents/#types-of-event (as I posted in comments) .
实际上,可以通过事件函数http://appjar.info/pythonEvents/#types-of-event (如我在评论中所述)触发ChangeFunction。
I used these two events to do this thing: 我使用以下两个事件来执行此操作:
app.setOptionBoxChangeFunction("optionbox", opt_changed)
app.setListBoxChangeFunction("list", lst_changed)
The whole working code here: 整个工作代码在这里:
from appJar import gui
def opt_changed(opt):
print(app.getOptionBox("optionbox"))
def lst_changed(lst):
print(app.getListBox("list")[0])
def press(btn):
if btn == "Cancel":
app.stop()
elif btn == "Show":
list_select()
else:
print('not defined yet')
def list_select():
app.infoBox("Info", "You selected " + app.getOptionBox("optionbox") + "\nBrowsing " + app.getListBox("list")[0])
app = gui("Database Editor", "500x500")
app.addOptionBox("optionbox", ["a", "b", "c", "d"])
app.addListBox("list", ["one", "two", "three", "four"])
app.setOptionBoxChangeFunction("optionbox", opt_changed)
app.setListBoxChangeFunction("list", lst_changed)
app.addButtons(["Show", "Cancel"], press)
app.go()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.