•  运行结果:https://s1.ax1x.com/2018/04/16/Ceuu4g.gif
  • # coding=gbk
    # 注意:输入框entry没有width、height属性
    # 注意:button中command=insert_cursor()是错误的,不能加括号
    #       也即button命令都是无参的函数
    # 运行结果:https://s1.ax1x.com/2018/04/16/Ceuu4g.gif
    import tkinter
    
    window = tkinter.Tk()
    window.title("jkn1234")
    window.geometry("500x500")
    
    # 文本框
    text = tkinter.Text(
        window,
        height=4
    )
    text.insert('end', '******************')
    text.pack()
    
    # 输入框, 注意:输入框entry没有width、height属性
    entry = tkinter.Entry(
        window,
        show='*'
    )
    entry.pack()
    
    def insert_cursor():
        var = entry.get()
        text.insert("insert", var)
    
    def insert_end():
        var = entry.get()
        text.insert("end", var)
    
    button1 = tkinter.Button(
        window,
        command = insert_cursor,
        text = "在光标处插入"
    )
    button1.pack()
    
    button2 = tkinter.Button(
        window,
        command = insert_end,
        text = "在结尾处插入"
    )
    button2.pack()
    
    window.mainloop()

     

相关文章:

  • 2022-02-27
  • 2022-12-23
  • 2021-08-23
  • 2022-12-23
  • 2021-12-19
  • 2022-02-09
猜你喜欢
  • 2022-12-23
  • 2021-09-13
  • 2022-12-23
  • 2022-12-23
  • 2021-08-13
  • 2021-12-18
相关资源
相似解决方案