pythontkinter label实验报告内容_pyhon之Tkinter学习Label

Label是标签

用法

Label(根对象, [属性列表])

属性

text    要现实的文本

bg    背景颜色

font    字体(颜色, 大小)

width  控件宽度

height 控件高度

控件属性设置有三种方式:

1.创建对象时,指定宽度与高度

2.使用属性width和height来指定宽度与高度

3.使用configure或config方法来指定宽度与高度

以上三种方式效果相同。

# -*- coding: utf-8 -*-

from Tkinter import *

root = Tk()

one = Label(root, text='one', width=30, height=1,bg="green", font=("Arial", 12))

one.pack()

two = Label(root, text='two',bg="red", font=("Arial", 12))

two['width'] = 30

two['height'] = 2

two.pack()

three = Label(root, text='three',bg="blue", font=("Arial", 12))

three.configure(width=30, height=3)

three.pack()

root.mainloop()

结果显示如下:

调整代码,让三个label同列显示:

#-*- coding: utf-8 -*-

from Tkinter import *root=Tk()

one= Label(root, text='one', width=30, height=1,bg="green", font=("Arial", 12))

one.pack(side=LEFT) #这里的side可以赋值为LEFT RTGHT TOP BOTTOM

two= Label(root, text='two',bg="red", font=("Arial", 12))

two['width'] = 30two['height'] = 2two.pack(side=RIGHT)

three= Label(root, text='three',bg="blue", font=("Arial", 12))

three.configure(width=30, height=3)

three.pack()

root.mainloop()

显示效果:

最后设置好Tkinter窗口的大小属性,一起看看效果

#-*- coding: utf-8 -*-

from Tkinter import *root=Tk()

root.title("hello world")

root.geometry('800x600')

root.resizable(width=False, height=False)

one= Label(root, text='one', width=30, height=1,bg="green", font=("Arial", 12))

one.pack(side=LEFT) #这里的side可以赋值为LEFT RTGHT TOP BOTTOM

two= Label(root, text='two',bg="red", font=("Arial", 12))

two['width'] = 30two['height'] = 2two.pack(side=RIGHT)

three= Label(root, text='three',bg="blue", font=("Arial", 12))

three.configure(width=30, height=3)

three.pack()

root.mainloop()

显示效果如下:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值