tkinter中的Entry和Text应用实例

13 篇文章 2 订阅

原文地址

分类目录——tkinter

  • 先看一下Entry和Text的效果

    EntryText

    其中上面为输入框,下面为Text展示框

  • tk.Entry()

    e = tk.Entry(window, show='*' , bg='#aaaaaa')   # 声明输入框
    # 输入框,可供传入的变量有: background, bd, bg, borderwidth, cursor,
    # exportselection, fg, font, foreground, highlightbackground,
    # highlightcolor, highlightthickness, insertbackground,
    # insertborderwidth, insertofftime, insertontime, insertwidth,
    # invalidcommand, invcmd, justify, relief, selectbackground,
    # selectborderwidth, selectforeground, show, state, takefocus,
    # textvariable, validate, validatecommand, vcmd, width,
    # xscrollcommand.
    # show='*',以*代替输入, = None,原始显示,不会被代替
    # bg    背景颜色
    # boderwidth    边框宽度
    e.pack()    # 放置输入框
    
  • tk.Text()

    t = tk.Text(window, height=2)
    # 放置一个文本框,用来显示
    # 可供传入的参数有
    # 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,
    t.pack(padx=10, pady=5)
    
  • 另外做了两个函数来通过两个按键操作Entry框和Text框

    def insert_point():
        var = e.get()   # 从输入框e获取值
        t.insert('insert', var)     # 插入到Text框的光标处
        # t.insert(1.1, var)  # 在(1,1)位置插入(索引从0开始)
    
    def insert_end():
        var = e.get()   # 从输入框e获取值
        t.insert('end', var)    # 插入到Text框的末尾
        
    b1 = tk.Button(window, text='inster point', width=15, height=2, command=insert_point)
    b1.pack(pady=5)    # 放置Button
    b2 = tk.Button(window, text='inster end', width=15, height=2, command=insert_end)
    b2.pack(pady=5)    # 放置Button
    
  • 全部代码

  • 参考文献

    代码主要来自Entry & Text 输入, 文本框,略有改动

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

BBJG_001

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值