zoukankan      html  css  js  c++  java
  • Tkinter 之Label标签

    一、参数说明

    语法作用
    Label(window,text=‘xxxxx’) 需要在界面显示的Label标签内容
    Label(window,text=‘xxxxx’,height=2) 组件的高度(所占行数)
    Label(root,text=‘xxxxx’,height=2,width=20) 组件的宽度(所占字符个数)
    Label(root,text=‘xxxxx’,fg='blue') 显示字体为蓝色
    Label(root,text=‘xxxxx’,bg=‘red’) 显示背景为红色
    Label(root,text=‘xxxxx’,justify=tk.LEFT) 多行文本的对齐方式
    Label(root,text=‘xxxxx’,padx=5) 文本左右两侧的空格数
    Label(root,text=‘xxxxx’,pady=5) 文本上下两侧的空格数
    Label(root,text=‘xxxxx’,font=("微软雅黑", 12)) 设置字体格式和大小
    Label(image=tk.PhotoImage(file="./image/loading.gif")) 设置背景图片
    Label(root,text=‘xxxxx’,image=photo,compound=tk.CENTER) 图像背景图位置
    Label(root,text=‘xxxxx’,anchor=tk.W) 设置文字位置

    二、代码示例

    import tkinter as tk
    
    window = tk.Tk()
    
    def main():
        global window
        # 设置主窗体大小
        winWidth = 600
        winHeight = 400
        # 获取屏幕分辨率
        screenWidth = window.winfo_screenwidth()
        screenHeight = window.winfo_screenheight()
        # 计算主窗口在屏幕上的坐标
        x = int((screenWidth - winWidth)/ 2)
        y = int((screenHeight - winHeight) / 2)
        
        # 设置主窗口标题
        window.title("Label参数说明")
        # 设置主窗口大小
        window.geometry("%sx%s+%s+%s" % (winWidth, winHeight, x, y))
        # 设置窗口宽高固定
        window.resizable(0,0)
        # 设置窗口图标
        window.iconbitmap("./image/icon.ico")
        
        """参数列表
    
            STANDARD OPTIONS
    
                activebackground, activeforeground, anchor,
                background, bitmap, borderwidth, cursor,
                disabledforeground, font, foreground,
                highlightbackground, highlightcolor,
                highlightthickness, image, justify,
                padx, pady, relief, takefocus, text,
                textvariable, underline, wraplength
    
            WIDGET-SPECIFIC OPTIONS
    
                height, state, width
    
            """
        # 只能传gif图片
        # cusor : wait 
        photo = tk.PhotoImage(file="./image/loading.gif")
        label = tk.Label(window, text="正在加载...", width=100,
                         font=("Arial", 12),justify=tk.LEFT,
                         bg="#ccc", fg="#f00", pady=10,
                         image=photo, compound=tk.TOP,
                         anchor="w", cursor="")
        label.pack()
        
        window.mainloop()
    
    if __name__ == '__main__':
        main()
    

      

    三、效果图

     

  • 相关阅读:
    How to produce the first draft of research paper?
    ETL
    BDA chapter 10
    <转>Java转iOS-第一个项目总结(2):遇到问题和解决方案
    <转>从Java转iOS第一个项目总结
    (转)总结iOS 8和Xcode 6的各种坑
    iOS开发之Xcode6之后不再自动创建Pch预编译文件,该如何解决这个问题?
    iOS开发:Objective-C中通知与协议的区别?
    PT和PX是什么鬼?
    使用cocoaPods经常出现的问题以及解决方案
  • 原文地址:https://www.cnblogs.com/yang-2018/p/11782466.html
Copyright © 2011-2022 走看看