是否可以在执行期间更改tkinter ListBox的selectmode?

时间:2017-06-16 14:56:50

标签: python tkinter listbox widget

让我们假设一个简单的tkinter表单最初在Listbox中使用selectmode=EXTENDED小部件定义。我想编写一个按钮,它将向表单添加高级选项,从而强制用户选择列表中的单个项目。这转换为更改为selectmode=SINGLE

我的代码无效。也许我根本无法重新定义Listbox,我应该以其他方式访问参数selectmode

class DefineMultiSelectForm(Frame):
    def __init__(self, master, listtodisplay=[]):
        Frame.__init__(self, master=master)
        self.listtodisplay=listtodisplay
        self.create_widgets()
        self.pack(fill=BOTH, expand=1)

    def create_widgets(self):
        self.listbox = Listbox(self,selectmode=EXTENDED, width=50)
        self.listbox.grid(row=0, column=0, columnspan=4, sticky=W+E+N+S)
        self.advanced_butt = Button(self, text="Advanced Editing", command=self.advanced)
        self.advanced_butt.grid (row=7, column=2, sticky=W+E)
        self.simplifd_butt = Button(self, text="Simple Editing", command=self.simple)
        self.simplifd_butt.grid (row=7, column=1, sticky=W+E)

    def advanced(self):
        self.listbox = Listbox(self,selectmode=SINGLE, width=50)

    def simple(self):
        self.listbox = Listbox(self,selectmode=EXTENDED, width=50)

非常感谢提前!

1 个答案:

答案 0 :(得分:2)

我不确定if 'username' in request.session: if request.method == 'POST': if 'image' in request.FILES: form = UploadImageForm(request.POST, request.FILES) if form.is_valid(): # Here goes the documentation code return HttpResponse(request.FILES['image'].content_type) //here i want to rename and move uploaded files else: return redirect('/upload_image') else: return redirect('/login/') 态度,但对于大多数tkinter属性,你可以改变它:

selectmode

你的方式不起作用的原因就是你所说的,你正在重新定义变量。