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()
非常感謝!這解決了我的問題。我感謝你的建議。 –