2017-08-21 7 views
1

こんにちは私はここで見つけた他の質問に基づいてリストボックスの選択に基づいてラベルを設定しようとしています。Listbox tkinterのcurselectionでラベルを設定するには

以下は、私が使用している関連コードです。私が正しく投稿していない場合は私の言い訳をしてください私は要求された関連コードだけを投稿しようとしており、これは実行時に発生するエラーを除いてすべて実行されます。

エラーは、次のとおりです。

#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) 
+0

あなたはすぐに 'の後に' '%を持っている、'、実際に違法な構文です。 '、'を削除する必要があります。 –

+0

@BryanOakleyこんにちはブライアン私は自分のコードでほぼ完成していて、あなたが私があまりに長く、貴重で少し説明するのを混乱させるかもしれないと思っていて、プライベートチャットや私の電子メールアドレスをフリックするので、私はあなたにリンクまたは.pyあなたの好みのいずれかをメールすることができます。あなたは時間を持っていないか、単に以前の助けのための心配thnxにしたくない場合! –

答えて

0

print 'You selected item %d: "%s"', % (index, value) SyntaxError: invalid syntaxはスパイダーとPython 3.6回答

import tkinter as tk 
root = tk.Tk() 
root.geometry("612x417") 
root.title("change label on listbox selection") 
root.resizable(0,0) 
root.configure(background='lightgrey') 


#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(evt): 
    # Note here that Tkinter passes an event object to onselect() 

    w = evt.widget 
    index = int(w.curselection()[0]) 
    value = w.get(index) 
# print ('You selected item %d: "%s"' % (index, value)) 
    frmcur_text.set(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.place(x=300,y=50) 
listbox2.place(x=300,y=125) 


for i in range(20): 
    i = i + 1 
    listbox1.insert(1, i) 
    listbox2.insert(1, i) 


listbox1.bind('<<ListboxSelect>>', onselect)  

cs = listbox1.curselection() 

frmcur_text.set(cs) 

root.mainloop() 
関連する問題