0
我想要一個按鈕來更改某個小部件的文本。用戶將按下啓動主功能的按鈕change_text
。然後該程序將等待,直到用戶將文本提供給Entry
,然後按下Enter
按鈕。 target_widget
將改變其文本,程序將繼續。程序暫停,直到用戶輸入文本並按下按鈕
下面是一些代碼類似於我的工作:
from Tkinter import *
root = Tk()
root.grid()
CIN = StringVar(root)
COUT = StringVar(root)
entry = Entry(root, textvariable = CIN)
prompt = Label(root, textvariable = COUT)
target_widget = Label(root, text = '')
enter_button = Button(root, command = proceed)
change_text_button = Button(root, command = change_text)
def change_text():
COUT.set("Enter text to entry")
# Wait until user presses enter_button
input_text = CIN.get()
target_widget['text'] = input_text
def proceed():
# continue program
pass
change_text_button.grid(row=0, column=0)
enter_button.grid(row=0, column=1)
target_widget(row=0, column=2)
prompt.grid(row=1, column=0)
entry.grid(row=1, column=1)
root.mainloop()
我如何有計劃等到用戶按下Enter
?
你忘了問一個問題。 – 2015-02-06 20:16:08