• Tkinter(二):Entry & Text


    效果图:

     在一个title为my window的容器内

    放入一个Entry组件,可以输入文本

    三个button,点击insert point,可将Entry中的文本展示在最下方的Text控件的光标所在处

    点击 insert end,会将Entry中的文本展示在最下方的Text控件文字的末尾

    点击delete可将Entry中的文本删除

    import tkinter as tk
    
    # 定义窗口
    window = tk.Tk()
    window.title('my window')  # 窗口title
    window.geometry('350x300')  # 窗口尺寸
    

    # 定义Entry e = tk.Entry(window, show=None, width=30, bd=4) e.pack() def insert_point(): # 得到Entry里面的值 varText = e.get() # 插入到光标所在位置 t.insert('insert', varText) def insert_end(): # 得到Entry里面的值 varText = e.get() # 插入到末尾 t.insert('end', varText) def delete(): e.delete(0, "end") # 定义button b1 = tk.Button(window, text='insert point', width=10, height=1, command=insert_point) b1.pack(pady=10) b2 = tk.Button(window, text='insert end', width=10, height=1, command=insert_end) b2.pack(pady=10) b3 = tk.Button(window, text='delete', width=10, height=1, command=delete) b3.pack(pady=10)
    # 定义Text t
    = tk.Text(window, width=20, height=8) t.pack() window.mainloop()

    其中用到的一些方法:

    get():获取文件框的值

    insert ( index, s ):向文本框中插入值,index:插入位置,s:插入值

    delete ( first, last=None ):删除文本框里直接位置值

    text.delete(10)      # 删除索引值为10的值
    text.delete(10, 20)  # 删除索引值从10到20之前的值
    text.delete(0, END)  # 删除所有值

      

  • 相关阅读:
    Servlet-获取页面的元素的值的方式以及区别
    Http请求-get和post的区别
    Servlet-xml配置简介以及url-pattern简介
    javaweb目录结构简介
    Servlet-生命周期简介
    tomcat-四种运行模式和三种部署模式(优化)
    命名空间System.IO
    Dictionary 字典
    导出-以虚拟表的形式获取数据源
    导入excel-uploadify+npoi
  • 原文地址:https://www.cnblogs.com/ronyjay/p/13265660.html
Copyright © 2020-2023  润新知