我想创建一个列表框,它会在点击按钮时出现和消失
这部分工作已经完成。但是如何像组合框一样在界面上列出这个列表呢
我试图用multiselection创建一个组合框(下面是一个示例),但很明显,只要单击其中一个元素,它就会关闭
import Tkinter as tk
class Example(tk.Frame):
def __init__(self, parent):
tk.Frame.__init__(self, parent)
menubutton = tk.Menubutton(self, text="Choose wisely",
indicatoron=True, borderwidth=1, relief="raised")
menu = tk.Menu(menubutton, tearoff=False)
menubutton.configure(menu=menu)
menubutton.pack(padx=10, pady=10)
self.choices = {}
for choice in ("Iron Man", "Superman", "Batman"):
self.choices[choice] = tk.IntVar(value=0)
menu.add_checkbutton(label=choice, variable=self.choices[choice],
onvalue=1, offvalue=0,
command=self.printValues)
def printValues(self):
for name, var in self.choices.items():
print "%s: %s" % (name, var.get())
if __name__ == "__main__":
root = tk.Tk()
Example(root).pack(fill="both", expand=True)
root.mainloop()
提前感谢您的帮助
目前没有回答
相关问题 更多 >
编程相关推荐