如何在Tkinter中显示组合框

时间:2018-05-30 14:56:24

标签: python tkinter

使用Tkinter为gui处理货币转换器的小项目。 我有下面的代码,但似乎我在组合框中有错误,因为它会抛出错误。

我错过了什么?

Currency1_value=0
Entry1=Entry(window,textvariable=Currency1_value)
Entry1.grid(row=1,column=0)

CurrencyCombo=Combobox(window, state="readonly", values=("one", "two", "three"))
CurrencyCombo.grid(row=1,column=1)

1 个答案:

答案 0 :(得分:0)

import tkinter as tk
from tkinter import ttk

root = tk.Tk()

combotext = tk.StringVar()
combotext.set('Select')

box = ttk.Combobox(root, textvariable=combotext, state='readonly')
box.pack()
box['values'] = ("Camembert",
                 "Brie",
                 "Tilsit",
                 "Stilton")

def callback_function(event):
    print('You selected:', combotext.get())

root.bind('<<ComboboxSelected>>', callback_function)

root.mainloop()