Tkinter——entry(文本框)和text(多行文本)
python入门常用操作:/qq_3330/article/details/112859327
import tkinter as tkfrom tkinter import fontwindow = tk.Tk()window.title('entry和text')window.geometry('400x400')# entry(类似于textbox 文本输入框)entry = tk.Entry(window, show=None, width=20)entry_password = tk.Entry(window, show='*')entry.pack()entry_password.pack()# buttondef insert_start():var = entry.get()# 在光标处插入值text.insert('insert',var)returndef insert_end():var = entry.get()# 在光标处插入值text.insert('end',var)returndef insert_position():var = entry.get()# 在光标处插入值# 2.2表示在第二行第二列插入vartext.insert(2.2,var)returnbutton_insertPoint = tk.Button(window,text='insert point',width = 20,height = 2,command = insert_start)button_insertEnd = tk.Button(window,text='insert end ',width = 20,height = 2,command = insert_end)button_insertPosition = tk.Button(window,text='第二行第二列插入 ',font = ('Helvetica', 12),width = 20,height = 2,command = insert_position)button_insertPoint.pack()button_insertEnd.pack()button_insertPosition.pack()# text(多行文本)text = tk.Text(window, height=5)text.pack()window.mainloop()
效果: