Tkinter 之Text文本框标签

一、参数说明

语法 作用
t=tk.Text()
t.insert(END,'插入的文本信息')
INSERT:光标的插入点
CURRENT:鼠标的当前位置所对应的字符位置
END:这个Textbuffer的最后一个字符
SEL_FIRST:选中文本域的第一个字符,如果没有选中区域则会引发异常
SEL_LAST:选中文本域的最后一个字符,如果没有选中区域则会引发异常
t.delete(mark1, mark2) INSERT:光标的插入点 CURRENT:鼠标的当前位置所对应的字符位置
END:这个Textbuffer的最后一个字符
SEL_FIRST:选中文本域的第一个字符,如果没有选中区域则会引发异常
SEL_LAST:选中文本域的最后一个字符,如果没有选中区域则会引发异常

二、代码示例

import tkinter as tk

window = tk.Tk()
# 设置主窗体大小
winWidth = 600
winHeight = 400
# 获取屏幕分辨率
screenWidth = window.winfo_screenwidth()
screenHeight = window.winfo_screenheight()
# 计算主窗口在屏幕上的坐标
x = int((screenWidth - winWidth)/ 2)
y = int((screenHeight - winHeight) / 2)

# 设置主窗口标题
window.title("Entry输入框参数说明")
# 设置主窗口大小
window.geometry("%sx%s+%s+%s" % (winWidth, winHeight, x, y))
# 设置窗口宽高固定
window.resizable(0,0)
# 设置窗口图标
window.iconbitmap("./image/icon.ico")

"""Construct a text widget with the parent MASTER.

    STANDARD OPTIONS

        background, borderwidth, cursor,
        exportselection, font, foreground,
        highlightbackground, highlightcolor,
        highlightthickness, insertbackground,
        insertborderwidth, insertofftime,
        insertontime, insertwidth, padx, pady,
        relief, selectbackground,
        selectborderwidth, selectforeground,
        setgrid, takefocus,
        xscrollcommand, yscrollcommand,

    WIDGET-SPECIFIC OPTIONS

        autoseparators, height, maxundo,
        spacing1, spacing2, spacing3,
        state, tabs, undo, width, wrap,

    """
def insert_end():
    text.insert(tk.END, "is end")
    
def insert():
    text.insert(tk.END, "is insert")
    
    
text = tk.Text(window, height=3)
text.pack()
tk.Button(window, text="end", width=30, pady=5, command=insert_end).pack(side=tk.TOP)
tk.Button(window, text="insert", width=30, pady=5, command=insert).pack(side=tk.TOP)

window.mainloop()

  

三、效果图

猜你喜欢

转载自www.cnblogs.com/yang-2018/p/11787385.html