zoukankan      html  css  js  c++  java
  • Python GUI编程(Tkinter)——Entry and Text

    #pack有先后次序!!
    import tkinter as tk
    window = tk.Tk() #新建窗口对象
    window.title('my window') #窗口名
    window.geometry('200x200')#窗口大小
    
    entry = tk.Entry(window,show=None)#新建entry对象,显示为原值
    #(如果show参数设置为show=something表示显示为something)
    entry.pack()
    
    text = tk.Text(window,height=2)#新建text对象,height为行数
    text.pack()
    
    def insert_point():
        variable = entry.get()
        text.insert('insert',variable)
        
    def insert_end():
        variable = entry.get()
        text.insert('end',variable)
        #参数还可以设置为具体位置(x,y):text.insert(x.y,variable)
    
    button_1 = tk.Button(window,text='insert point',
                       width=15,height=2,command=insert_point)#新建按钮,命令关联到hit_me这个函数
    button_1.pack()#放置按钮
    
    button_2 = tk.Button(window,text='insert end',
                       width=15,height=2,command=insert_end)
    button_2.pack()
    
    
    window.mainloop()#持续刷新window
    
    
    
  • 相关阅读:
    组件之间通信(父传子)
    flex布局
    ffmpeg解析TS流(转)
    swift之?和!的含义(转)
    Swift之画圆角添加多个枚举值方法
    swift之singleton
    swift之闭包
    Swift之fallthrough
    Selector
    Settings Bundle
  • 原文地址:https://www.cnblogs.com/zjx-pku/p/13358454.html
Copyright © 2011-2022 走看看