标签的各种属性

**代码展示:**
```
import tkinter as tk
root = tk.Tk()
root.geometry = '500x300'
label1 = tk.Label(root, text='龙王手游', width=50, height=10, bd=10)
label1.config(fg='white', bg='black', relief=tk.RAISED, font=('楷体', 10, 'overstrike'))

label2 = tk.Label(root, text='标签2', relief=tk.GROOVE, width=50, height=10, bd=2)

label2.config(fg='red', compound=tk.LEFT, bitmap='error', bg='yellow', font=('隶书', 10, 'bold'))

label3 = tk.Label(root, text='标签3', compound=tk.LEFT, bitmap='info', relief=tk.SUNKEN, width=50, height=10, bd=2)

label3.config(fg='white', bg='green', font=('隶书', -10, 'bold'))

label4 = tk.Label(root, text='标签4', width=50, height=10, bd=2)

label4.config(fg='white', bg='black', font=('楷书', -10, 'bold'))

label5 = tk.Label(root, text='标签5', width=50, height=10)

label5.config(fg='red', bg='yellow', bd=2, font=('隶书', 10, 'bold'))

label6 = tk.Label(root, text='标签6', width=50, height=10, bd=2)

label6.config(fg='white', bg='green', font=('隶书', 10, 'bold'))

label7 = tk.Label(root, text='标签7', width=50, height=10, bd=2)

label7.config(fg='white', bg='black', font=('隶书', 10, 'bold'))

label8 = tk.Label(root, text='标签8', width=50, height=10, bd=2)

label8.config(fg='red', bg='yellow', font=('隶书', 10, 'bold'))

label9 = tk.Label(root, text='标签9', width=50, height=10)

label9.config(fg='white', bg='green', bd=2, font=('隶书', 10, 'bold'))

label1.grid(row=0, column=0, ipadx=1, ipady=1)

label2.grid(row=0, column=1, padx=5, pady=5)

label3.grid(row=0, column=2, padx=1, pady=1)

label4.grid(row=1, column=0, ipadx=5, ipady=5)

label5.grid(row=1, column=1, padx=1, pady=1)

label6.grid(row=1, column=2, ipadx=5, ipady=5)

label7.grid(row=2, column=0, padx=1, pady=1)

label8.grid(row=2, column=1, ipadx=5, ipady=5)

label9.grid(row=2, column=2, padx=1, pady=1)

root.mainloop()

**结果:**

![](https://img2018.cnblogs.com/blog/1372901/201810/1372901-20181022185334636-1703718209.jpg)

<h1 style="background:cyan;">标签按钮合作案例</h1>
单击按钮是从新设置标签上的显示内容

import tkinter as tk # 导入tkinter库

root = tk.Tk() # 建立程序主窗口

root.title("Button按钮的使用") # 设置主窗口的标题

root.geometry('600x500')

------功能函数

def f1():

var.set("单击按钮1")

def f2():

var.set("单击按钮2")

def f3():

var.set("单击按钮3")

------建立标签

labelx = tk.Label(root)

labelx.config(width=10, height=5)

labelx.config(activebackground='red')

labelx.config(activeforeground='yellow')

labelx.config(relief=tk.SUNKEN)

labelx.config(anchor=tk.CENTER)

定义字符串变量

var = tk.StringVar()

labelx.config(textvariable=var)

------建立第一个按钮

button1 = tk.Button(root, text='按钮1')

button1.config(width=5, height=2)

button1.config(activebackground='red')

button1.config(activeforeground='yellow')

button1.config(anchor=tk.CENTER)

button1.config(bd=2)

button1.config(relief=tk.RAISED)

button1.config(font=('隶书', -20))

button1.config(command=f1)

------建立第二个按钮

button2 = tk.Button(root, text='按钮2')

button2.config(width=5, height=2)

button2.config(activebackground='red')

button2.config(activeforeground='yellow')

button2.config(anchor=tk.CENTER)

button2.config(bd=2)

button2.config(relief=tk.RAISED)

button2.config(font=('隶书', -20))

button2.config(command=f2)

------建立第三个按钮

button3 = tk.Button(root, text='按钮3')

button3.config(width=5, height=2)

button3.config(activebackground='red')

button3.config(activeforeground='yellow')

button3.config(anchor=tk.CENTER)

button3.config(bd=2)

button3.config(relief=tk.RAISED)

button3.config(font=('隶书', -20))

button3.config(command=f3)

各个组件排兵布阵

labelx.grid(row=0, column=1)

button1.grid(row=1, column=0)

button2.grid(row=1, column=1)

button3.grid(row=1, column=2)

root.mainloop()


<h1 style="background:cyan;">标签案例</h1>
在主窗口中定义了三个标签

import tkinter as tk

root = tk.Tk()

label1 = tk.Label(root, text='标签1')

label1.config(fg='white', bg='black')

label2 = tk.Label(root, text='标签2')

label2.config(fg='red', bg='yellow')

label3 = tk.Label(root, text='标签3')

label3.config(fg='white', bg='green')

label1.grid(row=0, column=3)

label2.grid(row=1, column=2)

label3.grid(row=1, column=1)

root.mainloop()

Python图形编程探索系列-08-再次认识标签的更多相关文章

  1. Python图形编程探索系列-09-tkinter与matplotlib结合案例

    案例1 案例来自于:https://bbs.csdn.net/topics/390326088 代码示例: import matplotlib matplotlib.use('TkAgg') from ...

  2. Python图形编程探索系列-07-程序登录界面设计

    设计任务 初步设计程序登录界面,详细分析设计步骤. 程序详细分析 基本框架设计 import tkinter as tk import tkinter.messagebox root = tk.Tk( ...

  3. Python图形编程探索系列-04-网上图片与标签组件的结合

    跳转到自己的博客 任务设定 任务:从网上找到一张图片,然后将其显示在标签上? 网上图片网站:http://pic.58pic.com/58pic/17/56/38/52w58PICtER_1024.j ...

  4. Python图形编程探索系列-03-标签组件(Label)

    跳转到自己的博客 tkinter.Label介绍 什么是标签? 通俗的将就相当于word的功能,能够进行显示不可修改的文字.图片或者图文混排. 直观体会一下 图1 背景图构成:内容区(黑色),填充区( ...

  5. Python图形编程探索系列-06-按钮批量生产函数

    设计任务 初步设计一个批量生产按钮的函数,根据需要的按钮数量,自动生成多少按钮. 函数设计 import tkinter as tk # 导入tkinter库 root = tk.Tk() # 建立程 ...

  6. Python图形编程探索系列-05-用控制变量构建对话程序

    跳转到自己的博客 控制变量 变量 符号 意义 默认值 1 var = tk.BooleanVar() 布尔型 0 2 var = tk.StringVar() 字符串控制变量 空字符串 3 var = ...

  7. Python图形编程探索系列-02-框架设计

    跳转到我的博客 设计任务 在主窗口root中放置三个容器用于容纳组件,容器采用框架设计. 代码初步设计 import tkinter as tk root = tk.Tk() root.geometr ...

  8. Python图形编程探索系列-01-初级任务

    设计任务 设计一个主窗口,在其中添加三个标签和三个按钮,当点击按钮时,对标签的内容和色彩进行修改. 代码初步设计 import tkinter as tk root = tk.Tk() def f1( ...

  9. linux python 图形编程 qt开发环境搭建

    我的系统是 ubuntu14.04 我们使用的是python2.7,建议安装qt4+pyqt4+eric4 eric是pyqt的界面设计器的代码生成软件. 1.安装sip 这个是python和qt之间 ...

随机推荐

  1. C++学习8-面向对象编程基础(模板)

    模板 模板是一种工具,模板可以使程序员能建立具有通用类型的函数库与类库: 模板具有两种不同的形式: 函数模板 类模板 函数模板 当一个add()函数接收两个参数,因为某种特定情况,所传入的实参数据类型 ...

  2. 算法时间复杂度和NP问题简介

    这里主要简单说一下算法的时间复杂度和NP问题简介,毕竟分析算法的时间复杂度上界有助于分析算法的好坏,分析算法好坏也有助于分析是否还有更好的算法: 一.时间复杂度: 一般关心的还有递归问题中的时间复杂度 ...

  3. java中不同类型的数值占用字节数

    在Java中一共有8种基本数据类型,其中有4种整型,2种浮点类型,1种用于表示Unicode编码的字符单元的字符类型和1种用于表示真值的boolean类型.(一个字节等于8个bit) 1.整型 类型 ...

  4. Jenkins中配置selenium测试

    Jenkins中配置selenium测试 2015/03/23 第一步在jenkins中配置selenium服务器 第二步工程配置: 第三步:执行构建: 第四步,查看报告:

  5. elasticsearch5.0.1集群一次误删除kibana索引引发的血案

    elasticsearch集群中一次删除kibana索引引发的血案 1.问题发生的过程: 早上的时候有某个索引无法看到报表数据,于是就点该报表多次,估计集群被点挂了,报错:Elasticsearch ...

  6. centos6.5下编译安装mariadb-10.0.20

    源码编译安装mariadb-10.0.20.tar.gz 一.安装cmake编译工具 跨平台编译器 # yum install -y gcc* # yum install -y cmake 解决依赖关 ...

  7. SKlearn库学习曲线

    思想: # 1.现将所有样本用交叉验证方法或者(随机抽样方法) 得到 K对 训练集-验证集# 2.依次对K个训练集,拿出数量不断增加的子集如m个,并在这些K*m个子集上训练模型.# 3.依次在对应训练 ...

  8. TCP/IP、Http大纲

    TPC/IP协议是传输层协议,主要解决数据如何在网络中传输,而HTTP是应用层协议,主要解决如何包装数据.关于TCP/IP和HTTP协议的关系,网络有一段比较容易理解的介绍:“我们在传输数据时,可以只 ...

  9. Spark的HA部署

    一.安装JDK.Scala 二.安装zookeeper 三.安装Hadoop 四.安装Spark 1.修改spark/conf/spark-env.sh export JAVA_HOME=/usr/j ...

  10. LeetCode(48):旋转图像

    Medium! 题目描述: 给定一个 n × n 的二维矩阵表示一个图像. 将图像顺时针旋转 90 度. 说明: 你必须在原地旋转图像,这意味着你需要直接修改输入的二维矩阵.请不要使用另一个矩阵来旋转 ...