Python tkinterc Combobox
时间: 2023-11-19 07:00:16 浏览: 90
The tkinter Combobox widget is used to display a dropdown list of items from which a user can select one item. It is similar to a dropdown list in HTML.
Here is an example of how to create a Combobox in Python tkinter:
```
from tkinter import *
from tkinter.ttk import Combobox
root = Tk()
root.geometry("300x200")
# create a list of items for the Combobox
items = ["Apple", "Banana", "Cherry", "Grape", "Orange"]
# create a Combobox with the list of items
combo = Combobox(root, values=items)
combo.pack()
root.mainloop()
```
In this example, we import the tkinter and Combobox modules, create a list of items, and create a Combobox object with the list of items. We then pack the Combobox into the root window and start the main event loop.
The user can click on the Combobox to display the list of items, and then select one item from the list. The selected item will be displayed in the Combobox.
阅读全文