zoukankan      html  css  js  c++  java
  • 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() 并打印


    常用软件开发学习资料目录:  

    1.经典编程电子书收藏  

    2.C&C++编程学习资料收藏   

    3.算法及数据结构(有关c,c++,java)   

    4.Java开发学习资料收藏      

    5.Android开发学习资料收藏  

    6.Python开发学习资料收藏  

    7.大数据,机器学习,人工智能资料收藏

    8.Docker资料收藏

  • 相关阅读:
    adapter 异步加载
    退出应用
    scrollview 和 edittext 焦点冲突
    判断字符串
    generate portable version cannot addon plugin(buffer var)
    在ubuntu上面安装perl
    TV
    关于xilinx ise10.1与modelsim仿真库编译
    迅雷tips
    Verilog log2 函数
  • 原文地址:https://www.cnblogs.com/it-tsz/p/10582501.html
Copyright © 2011-2022 走看看