【发布时间】:2017-08-21 18:26:13
【问题描述】:
您好,我正在尝试根据我在此处找到的其他一些问题根据列表框选择设置标签。
以下是我正在使用的相关代码。如果我没有正确发布,请原谅我正在尝试仅按要求发布相关代码,除了运行时出现的错误之外,所有这些都运行。
错误是:print 'You selected item %d: "%s"', % (index, value)
SyntaxError: invalid syntax
#Show selected currency for from in label
frmcur_text = tk.StringVar()
frmcur = tk.Label(root, textvariable=frmcur_text, font="Helvetica 10 bold", anchor='w', background='lightgrey').place(x=195,y=50)
def onselect(event):
# Note here that Tkinter passes an event object to onselect()
w = event.Listbox
index = int(w.curselection()[0])
value = w.get(index)
print 'You selected item %d: "%s"', % (index, value)
#Create listboxes for xurrency selection
listbox1 = tk.Listbox(root, font="Helvetica 11 bold", height=3, width=10)
listbox2 = tk.Listbox(root, font="Helvetica 11 bold", height=3, width=10)
listbox1.bind('<<ListboxSelect>>', onselect)
cs = listbox1.curselection()
frmcur_text.set(cs)
【问题讨论】:
-
%紧跟在,之后,这确实是非法语法。您需要删除,。 -
@BryanOakley 嗨 Bryan 我的代码差不多完成了,想知道您是否愿意帮我解决一些逻辑混乱,我不想在这里发布太长、有价值和有点令人困惑的解释也许你可以打开一个私人聊天或轻弹我的电子邮件地址,这样我就可以通过电子邮件向你发送链接或 .py 当然你的偏好。如果您没有时间或只是不想担心,请寻求以前的帮助!!!
标签: python-3.x select tkinter listbox listboxitem