zoukankan      html  css  js  c++  java
  • tkinter第二章(添加图片,背景图片)

    #插入文件图片
    import tkinter as tk

    root = tk.Tk()

    #创建一个标签类, [justify]:对齐方式
    textLabel = tk.Label(root,text="你在右边会看到一个图片, 我在换个行",
    justify = tk.LEFT)#左对齐
    textLabel.pack(side=tk.LEFT)#自动对齐,side:方位

    #创建一个图片管理类
    photo = tk.PhotoImage(file="18.png")#file:t图片路径
    imgLabel = tk.Label(root,image=photo)#把图片整合到标签类中
    imgLabel.pack(side=tk.RIGHT)#自动对齐


    tk.mainloop()

    import tkinter as tk

    root = tk.Tk()


    #增加背景图片
    photo = tk.PhotoImage(file="背景.png")
    theLabel = tk.Label(root,
             text="我是内容, 请你阅读",#内容
             justify=tk.LEFT,#对齐方式
             image=photo,#加入图片
             compound = tk.CENTER,#关键:设置为背景图片
             font=("华文行楷",20),#字体和字号
             fg = "white")#前景色
    theLabel.pack()

    tk.mainloop()

    #插入文件图片
    import tkinter as tk

    root = tk.Tk()

    frame1 = tk.Frame(root)#这是上面的框架
    frame2 = tk.Frame(root)#这是下面的框架


    var = tk.StringVar()#储存文字的类
    var.set("你在右边会看到一个图片, 我在换个行")#设置文字

    #创建一个标签类, [justify]:对齐方式,[frame]所属框架
    textLabel = tk.Label(frame1,textvariable=var,
             justify = tk.LEFT)#显示文字内容
    textLabel.pack(side=tk.LEFT)#自动对齐,side:方位

    #创建一个图片管理类
    photo = tk.PhotoImage(file="18.png")#file:t图片路径
    imgLabel = tk.Label(frame1,image=photo)#把图片整合到标签类中
    imgLabel.pack(side=tk.RIGHT)#自动对齐


    def callback():#触发的函数
      var.set("你还真按了")#设置文字

    #[frame]所属框架 ,text 文字内容 command:触发方法
    theButton = tk.Button(frame2,text="我是下面的按钮",command=callback)
    theButton.pack()#自动对齐

    frame1.pack(padx=10,pady=10)#上框架对齐
    frame2.pack(padx=10,pady=10)#下框架对齐


    tk.mainloop()

  • 相关阅读:
    Qt音视频开发24-ffmpeg音视频同步
    Qt编写的项目作品34-雷达模拟仿真工具(雨田哥作品)
    Qt编写的项目作品33-斗图神器(雨田哥作品)
    Qt编写的项目作品32-定制化安装包工具(雨田哥作品)
    Qt编写的项目作品31-PDF阅读器(雨田哥作品)
    Caused by: com.rabbitmq.client.ShutdownSignalException: channel error; protocol method: ......
    com.alibaba.fastjson.JSONException: syntax error, pos 1
    chrome技巧
    pip强制重装
    javascript添加url querystring
  • 原文地址:https://www.cnblogs.com/banzhen/p/7427201.html
Copyright © 2011-2022 走看看