这是我今天早些时候提出的同样的问题,以及您尝试帮助我的几个问题,但是我无法使其工作。我想要做的就是用我在单击列表框时选择的多个选项填充“ichose”。Python中的问题从Tkinter列表框中获取多个选择
import Tkinter as tk
from Tkinter import *
global ichose
class App(tk.Frame):
def __init__(self, master):
tk.Frame.__init__(self,master)
self.master=master
self.grid()
self.ichose =()
self.l = Listbox(self, height=10, selectmode=EXTENDED)
# Selectmode can be SINGLE, BROWSE, MULTIPLE or EXTENDED. Default BROWSE
self.l.grid(column=0, row=0, sticky=(N,W,E,S))
self.l.bind("Double-Button-1", self.entered)
s = Scrollbar(self, orient=VERTICAL, command=self.l.yview)
s.grid(column=0, row=0, sticky=(N,S,E))
self.l['yscrollcommand'] = s.set
for i in range(1,101):
self.l.insert('end', 'Line %d of 100' % i)
def entered(self, event):
self.ichose = self.selection_get()
self.ichose = ('hello')
root=tk.Tk()
root.title('Listbox Problem')
root.geometry('200x200')
app=App(root)
root.mainloop()
print app.ichose
不管我做什么,“ichose”作为一个空元组()出现。 很明显,“进入”功能从来没有被调用,因为我从来没有看到测试字符串'你好'。
我也不知道“双按钮”,“<>”等各种选项是什么,我在哪里可以找到每一个列表和解释?
如果有人可以请只修改我的程序,使“打印毛榉糖”的作品,我会很感激。你可以从我的程序中看到,我并不真正知道自己在做什么,但热衷于学习。谢谢。