python ttk控件_记Python Tkinter控件学习1

Label——标签控件,可显示文本

参数

win:父窗体

text:显示文本的内容

bg:背景色

fg:字体色

font:font是一个元组

width:宽

height:高

wraplength:行宽

justify:设置换行后的对齐方式

anchor:设置方位 n s w e center 可以组合使用

label = tkinter.Label(win,

text='first Label',

bg='blue', fg='red',

font=('黑体', 25),

wid=10,

height=10,

wraplength=100,

justify='left',

anchor='w'

)

Button——按钮控件

参数

win:父窗体

text:按钮文字

command:点击按钮执行动作(可以是lambda表达式或函数名)

def hello():

print('hello world')

button = tkinter.Button(win, text="按钮", command=hello)

Entry——输入控件

参数

show:密文显示字符

e = tkinter.Variable()(e可理解为输入框对象)

entry = tkinter.Entry(win, textvariable=e)

e.set("value") #设置值

print(e.get()) #获取值

Text——用于显示多行文本

参数

win:父窗体

height:行数

width:行宽

text.insert()文本框内容插入方法

text = tkinter.Text(win, wid=30, height=4)

str = 'I am the bone of my sword.Steel is my body,and fire is my blood.I have created over a thousand blades.Unknown to Death.Nor known to Life'

text.insert(tkinter.INSERT, str)

滚动条

滚动条设置的关键在于滚动条和控件的关联

import tkinter

win = tkinter.Tk()

text = tkinter.Text(win, wid=30, height=4)

str = 'I am the bone of my sword.Steel is my body,and fire is my blood.I have created over a thousand blades.Unknown to Death.Nor known to Life'

text.insert(tkinter.INSERT, str)

scroll = tkinter.Scrollbar()

# 设置位置

scroll.pack(side=tkinter.RIGHT, fill=tkinter.Y)

text.pack(side=tkinter.LEFT, fill=tkinter.Y)

# 关联(此处的关联的单方的)

scroll.config(command=text.yview) #滚动条向文本框关联

text.config(yscrollcommand=scroll.set) 文本框向滚动条关联

win.mainloop()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值