• (2)python tkinter-按钮.标签.文本框、输入框


    按钮

    无功能按钮

    Button的text属性显示按钮上的文本
    tkinter.Button(form, text='hello button').pack() 

    无论怎么变幻窗体大小,永远都在窗体的最上行的居中位置

    点击触发事件

    Button 的 command属性调用方法,来执行事件

    例如有个方法

    def a():
        print ('已点击按钮')
    tkinter.Button(form, text='hello button',command=a).pack() 

     点击3次按钮,执行了3次 a方法

    设置按钮的宽、高  width,height 属性

    方法一

    tkinter.Button(form, text='hello button',width=10,height=1).pack()  

    或者(注意第一行没有.pack())

    t1=tkinter.Button(form, text='button')

    方法二

    t1['width']=20
    t1['height']=2
    t1.pack()

    方法三

    t1.configure(width = 30,height = 3)
    t1.pack()

    按钮状态 state 属性

    默认是 NORMAL,还有一个状态是active目前不知道什么作用

    禁用

    tkinter.Button(form, text='hello button',width=10,height=1,state=tkinter.DISABLED).pack()  

    按钮的前景色与背景色 

    fg:  前景色(字体颜色)

    tkinter.Button(form, text='hello button',width=10,height=1,fg='red').pack()  

     bg:背景色 

    tkinter.Button(form, text='hello button',width=10,height=1,bg='blue').pack()

     文本在按钮上的显示位置

    属性 anchor

    它的值有这8个方向

    n(north),s(south),w(west),e(east)和ne,nw,se,sw,

     已西北方向为例子

    tkinter.Button(form, text='hello button',width=20,height=5,anchor='nw').pack()

     按钮风格

    属性 relief

    tkinter.Button(form, text='hello button', relief=FLAT).pack()

    测试没成功。。。。。。????

     

    标签Label

    lab1=tkinter.Label(form,text='标签:').pack()

     

     

    文本框 text

    t1=tkinter.Text(form,width = 10,height = 1).grid(row=0,column=1)

     给文本框赋值

    t1.insert(1.0,'abc')

    那个1.0是什么意思,暂时不懂

    取出文本框的值

     

    输入框 Entry

    给输入框赋值初始值

    绑定tkinter.StringVar()后 set()

    t1 = tkinter.StringVar()
    t1.set('春季里那个百花开')
    entry = tkinter.Entry(root, textvariable = t1).pack()
    print (t1.get())

    获取输入框的值 t1.get() 并打印

  • 相关阅读:
    在JAVA应用中远程提交MapReduce程序至Hadoop集群运行
    ImpalaJDBCDriver 500051
    在Linux上安装Python3
    MySQL导入之mysqlimport
    hadoop mapreduce的本地模式及yarn模式
    MySQL之mysqldump的使用
    MapReduce的本地运行模式(debug调试)
    09 MySQL触发器
    P3168 [CQOI2015]任务查询系统
    P4124[CQOI]手机号码
  • 原文地址:https://www.cnblogs.com/buchizaodian/p/7072550.html
Copyright © 2020-2023  润新知