tkinter输入框
时间: 2023-09-10 12:06:12 浏览: 83
在tkinter中,可以使用Entry方法创建一个输入框。例如引用中的代码可以创建一个简单的输入框:
```
import tkinter as tk
window = tk.Tk()
window.title("Python tkinter教程-04:输入框 by 罗富茗")
e = tk.Entry(window)
e.pack()
window.mainloop()
```
而引用中的代码则是在创建输入框时设置了字体、背景色和前景色等属性。例如:
```
import tkinter as tk
window = tk.Tk()
window.title("Python tkinter教程-04:输入框 by 罗富茗")
e = tk.Entry(window, font=("kaiti", 20), bg="red", fg="green")
e.pack()
window.mainloop()
```
如果想要获取输入框中的内容,可以使用get()方法。例如引用中的代码可以获取输入框中的内容并打印出来:
```
import tkinter as tk
window = tk.Tk()
window.title("Python tkinter教程-03:按钮 by 罗富茗")
e = tk.Entry(window)
e.pack()
def get():
print("你输入了:" + e.get())
b = tk.Button(window, text="获取输入内容", command=get)
b.pack()
window.mainloop()
```<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* *3* [Python tkinter教程-04:输入框](https://blog.csdn.net/weixin_42725873/article/details/105874434)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 100%"]
[ .reference_list ]
阅读全文