按钮

无功能按钮

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方法

python tkinter-按钮.标签.文本框、输入框_文本框


设置按钮的宽、高  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()


python tkinter-按钮.标签.文本框、输入框_输入框_02


 bg:背景色 

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


python tkinter-按钮.标签.文本框、输入框_tkinter_03


 文本在按钮上的显示位置

属性 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()


python tkinter-按钮.标签.文本框、输入框_输入框_04


 按钮风格

属性 relief

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


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



标签Label

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


python tkinter-按钮.标签.文本框、输入框_文本框_05




文本框 text

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


python tkinter-按钮.标签.文本框、输入框_背景色_06

 给文本框赋值

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())



python tkinter-按钮.标签.文本框、输入框_背景色_07


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

python tkinter-按钮.标签.文本框、输入框_文本框_08


常用软件开发学习资料目录(详见​​我爱分享资源论坛​​):  

1.​​经典编程电子书​​收藏  

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

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

4.​​Java开发学习资料收藏​​      

5.​​Android开发学习资料​​收藏  

​​6.Python开发学习资料收藏 ​​ 

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

8.​​Docker资料收藏​​




按钮

无功能按钮

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方法

python tkinter-按钮.标签.文本框、输入框_文本框


设置按钮的宽、高  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()


python tkinter-按钮.标签.文本框、输入框_输入框_02


 bg:背景色 

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


python tkinter-按钮.标签.文本框、输入框_tkinter_03


 文本在按钮上的显示位置

属性 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()


python tkinter-按钮.标签.文本框、输入框_输入框_04


 按钮风格

属性 relief

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


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



标签Label

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


python tkinter-按钮.标签.文本框、输入框_文本框_05




文本框 text

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


python tkinter-按钮.标签.文本框、输入框_背景色_06

 给文本框赋值

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())



python tkinter-按钮.标签.文本框、输入框_背景色_07


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

python tkinter-按钮.标签.文本框、输入框_文本框_08