【发布时间】:2020-03-05 00:31:40
【问题描述】:
我正在尝试制作一个程序,其中一个功能是从 ListBox 中获取用户选择的选项并将它们显示在弹出窗口中,但我一直不知道在哪里以及如何使用 .get() .
代码如下:
# Adds Listbox
self.toppings_label = Label(self, text="Toppings:")
self.toppings_label.grid(row=3, column=0)
self.toppings_selection = Listbox(self, selectmode="multiple")
self.toppings_selection.grid(row=3, column=1, columnspan=3)
self.toppings_selection.insert(1, "Pepperoni")
self.toppings_selection.insert(2, "Sausage")
self.toppings_selection.insert(3, "Green Peppers")
self.toppings_selection.insert(4, "Olives")
self.toppings_selection.insert(5, "Chicken")
…
toppings = self.toppings_selection.get()
mb.showinfo("Confirm", "Toppings: " + toppings)
【问题讨论】:
-
您可以添加
Button()来运行函数(按下按钮时),该函数使用.get() 从列表框中获取选定数据。