我想要實作的是能夠單擊一個按鈕并獲取用戶輸入到變數中的文本。
我已經有一個按鈕和文本框
from tkinter import *
def Enter_button():
print()
ws = Tk()
ws.title('quick look up')
ws.geometry('300x300')
ws.config(bg='#ffffff')
message ='''Data here:'''
text_box = Text(
ws,
height=13,
width=40
)
text_box.pack(expand=True)
text_box.insert('end', message)
Button(
ws,
text='Submit',
width=15,
height=2,
command=Enter_button
).pack(expand=True)
ws.mainloop()
uj5u.com熱心網友回復:
Enter_button您可以在某處添加text_box.get("1.0",END).
get()獲取要獲取的文本的開始索引和結束索引。所以對于所有的文本使用:.get("1.0",END)如上圖和下圖所示。
因此,例如:
from tkinter import *
def Enter_button():
print(text_box.get("1.0",END))
ws = Tk()
ws.title('quick look up')
ws.geometry('300x300')
ws.config(bg='#ffffff')
message ='''Data here:'''
text_box = Text(
ws,
height=13,
width=40
)
text_box.pack(expand=True)
text_box.insert('end', message)
Button(
ws,
text='Submit',
width=15,
height=2,
command=Enter_button
).pack(expand=True)
ws.mainloop()
uj5u.com熱心網友回復:
如果您希望能夠更改它,您必須使用一些文本創建變數,然后銷毀并重建標簽以更新它
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/405992.html
標籤:
