0
我正在尝试创建一个ttk.Combobox。用户选择一个值后,下拉列表将消失并暂停一秒钟,然后显示结果。Tkinter,选择Combobox后暂停
我在几个不同的位置尝试x.after(1000)。它可以是GUI打开时的暂停或下拉列表中的暂停(即,下拉列表在1000毫秒之前不会消失)。
是否可以在选择该值后暂停并且下拉消失?
import tkinter as tk
from tkinter import ttk
class App():
def __init__(self, root):
# Main Frame
frame = ttk.Frame(root)
frame.grid(column=0, row=0, sticky='WESN')
self.test_lf = ttk.LabelFrame(frame, text='Test')
self.test_lf.grid(column=0, row=0, padx=5, sticky='WE')
self.selection = tk.StringVar()
self.selection.trace('w', self.result)
options = ttk.Combobox(self.test_lf, textvariable=self.selection, width=10)
options['values'] = ('A', 'B', 'C')
options.grid(column=0, row=0, sticky='WE', columnspan=2)
# options.after(1000) # Pause when open
result_label = ttk.Label(self.test_lf, text='Result:')
result_label.grid(column=0, row=2, sticky='W')
def result(self, *args):
selection_value=self.selection.get()
selection_result = ttk.Label(self.test_lf, text=selection_value)
selection_result.grid(column=1, row=2)
# selection_result.after(1000) # Pause on drop down list
root = tk.Tk()
root.title('Sample')
app = App(root)
root.mainloop()
非常感谢!这解决了我的问题。我感谢你的建议。 –