首页
学习
活动
专区
圈层
工具
发布
    • 综合排序
    • 最热优先
    • 最新优先
    时间不限
  • 来自专栏python3

    tkinter -- Label颜色,长宽设置

    的标题 # 创建一个label,label...... labe1 = Label(root, fg='red', bg='blue', text='tkinter1')  # image=bm(实例化PhotoImage 的对象) labe2 = Label(root, fg='red', bg='yellow', text='tkinter2')  # image=bm(实例化PhotoImage的对象) labe3  = Label(root, fg='red', bg='green', text='tkinter3')  # image=bm(实例化PhotoImage的对象) labe4 = Label(root , fg='red', bg='lightblue', text='tkinter4')  # image=bm(实例化PhotoImage的对象) # 颜色还可以使用#RRGGBB labe5 = Label (root, fg='red', bg='#FF00FF', text='tkinter5')  # image=bm(实例化PhotoImage的对象) # 显示label for i in range

    5.6K10发布于 2018-08-02
  • 来自专栏IT杂谈学习

    已解决:_tkinter.TcLError: couldn’t recognize data in image file “Image/nakamuraan.gif”

    不支持的图片格式:Tkinter的PhotoImage类只支持GIF和PGM/PPM格式,不支持其他格式如JPEG或PNG。 文件读取权限问题:如果程序没有权限读取图片文件,也会导致该错误。 以下是一个可能导致该错误的代码示例: import tkinter as tk # 创建Tkinter窗口 root = tk.Tk() # 尝试加载并显示图片 try: img = tk.PhotoImage loading image: {e}") # 启动Tkinter主循环 root.mainloop() 解释错误之处: 如果图片文件“Image/nakamuraan.gif”不存在或路径不正确,tk.PhotoImage 如果图片文件的格式不正确或已损坏,tk.PhotoImage也会抛出相同的错误。 四、正确代码示例 为了解决此错误,我们可以采取以下步骤: 确保图片文件存在且路径正确。 使用ImageTk.PhotoImage将Pillow图片转换为Tkinter可用的格式。 使用try-except块捕获并处理可能的文件读取错误。

    1.6K10编辑于 2024-07-01
  • 来自专栏叶子陪你玩编程

    【tkinter系列 第九课 Canvas窗口部件 】

    root = Tk() root.geometry("400x200") w = Canvas(root, width=200, height=100,bg="yellow") w.pack() # 使用PhotoImage 方法加载图片 photo = PhotoImage(file="test.png") # 显示图片 前面两个数字表示图片显示位置 锚点默认图片中心 anchor参数可以更改锚点 w.create_image 代码: from tkinter import * root = Tk() root.geometry("400x200") # 使用PhotoImage方法加载图片 photo = PhotoImage

    1.5K11发布于 2020-03-12
  • 来自专栏sktj

    python tkinter pil 缩略图 脚本

    import * from PIL import Image # <== required for thumbs from PIL.ImageTk import PhotoImage return thumbs class ViewOne(Toplevel): """ open a single image in a pop-up window when created; photoimage imgfile): Toplevel.init(self) self.title(imgfile) imgpath = os.path.join(imgdir, imgfile) imgobj = PhotoImage main app window, or Frame container (pack); imgfile differs per loop: must save with a default; photoimage row = Frame(win) row.pack(fill=BOTH) for (imgfile, imgobj) in thumbsrow: photo = PhotoImage

    61130编辑于 2022-05-13
  • 来自专栏跟Qt君学编程

    翻译 | QML编码约定

    使查找对象变得很容易 property bool thumbnail: false // 自定义属性声明 property alias image: photoImage.source 信号声明 function doSomething(x) // js函数 { return x + photoImage.width 20 height: 150 width: { // 复杂绑定 if (photoImage.width > 200) { photoImage.width; } else { 200; } } Rectangle id: border anchors.centerIn: parent; color: "white" Image { id: photoImage

    1.2K20发布于 2020-02-14
  • 来自专栏python3

    tkinter -- Label之bitmap使用方法

    示例: from tkinter import * root = Tk()  # 初始化TK # 实例化PhotoImage类,需要传一个gif图片路径 bm = PhotoImage(file='. /111.gif') # 创建一个label label = Label(root, image=bm)  # image=bm(实例化PhotoImage的对象) # 显示label label.pack

    1.5K20发布于 2018-08-02
  • 来自专栏python基础文章

    Python编程 简单春节倒计时教程(附源代码)

    2.PHotoimage 函数 在Tkinter中,一些小部件可以显示图像,例如Label和Button。这些小部件采用允许它们显示图像的图像参数。 用 PHotoimage 函数设置一个图片对象 img = tk.PhotoImage(file = "1111.png") 背景图(自取) 图片 注意:图片格式要为.png格式,将图片存放到 你Python ") # 主窗口 600x400 大小 root.title("salted fish") # 设置主窗口标题内容 "salted fish" img = tk.PhotoImage (file = "1111.png") # 用 PHotoimage 函数设置一个图片对象 bg_labe =tk.Label(root,

    1.3K30编辑于 2023-10-15
  • 来自专栏sktj

    python pyphoto图片查看器

    from PIL import Image # PIL Image: also in tkinter from PIL.ImageTk import PhotoImage return thumbs class ViewOne(Toplevel): """ open a single image in a pop-up window when created; photoimage main app window, or Frame container (pack); imgfile differs per loop: must save with a default; photoimage class ViewOne(Toplevel): """ open a single image in a pop-up window when created; a class because photoimage numcols], thumbs[numcols:] colpos = 0 for (imgfile, imgobj) in thumbsrow: photo = PhotoImage

    1.9K50编辑于 2022-05-13
  • 来自专栏Python小屋

    Python使用tkinter编写图片浏览程序

    代码要点:1)使用tkinter的Label显示图片;2)tkinter的PhotoImage支持的图片格式较少,使用pillow扩展库的Image和ImageTk弥补了这个缺点。 400 if h>600: w = int(w*600/h) h = 600 im = im.resize((w,h)) # 创建PhotoImage 对象,并设置Label组件图片 im1 = ImageTk.PhotoImage(im) lbPic['image'] = im1 lbPic.image

    3.6K90发布于 2018-04-17
  • 来自专栏进步集

    【python】如何用canvas在自己设计的软件上作画

    文章目录 前言 Canvas组件 Canvas画布界面 画长方体 画多边形 PhotoImage组件 展示gif的图片 展示gif法2 总结 前言 python学习之路任重而道远,要想学完说容易也容易 coding=gbk import os from tkinter import * t1=Tk() c1=Canvas(t1,width=200,height=200) c1.pack() img=PhotoImage coding=gbk import os from tkinter import * t1=Tk() c1=Canvas(t1,width=200,height=200) c1.pack() img=PhotoImage 你可以使用Tkinter库中的PhotoImage类来创建一个图片对象,并将其放置在窗口中。这个组件支持多种图片格式,例如GIF、JPEG、PNG等。 import * import os filename=os.path.abspath(os.path.curdir)+'\\xxzz.gif' print(filename) root=Tk() img=PhotoImage

    1.9K20编辑于 2023-03-11
  • 来自专栏sktj

    python3 五子棋(tkinter)

    Canvas cv = Canvas(root, background='white', width=BOARD_WIDTH, height=BOARD_HEIGHT) cv.pack() bm = PhotoImage images/board.png") cv.create_image(BOARD_HEIGHT/2 + 1, BOARD_HEIGHT/2 + 1, image=bm) selectedbm = PhotoImage 移动红色选择框 cv.coords(selected,(selectedX * X_RATE + X_OFFSET, selectedY * Y_RATE + Y_OFFSET)) black = PhotoImage (file="images/black.gif") white = PhotoImage(file="images/white.gif") def click_handler(event): #

    1.2K10发布于 2019-12-12
  • 来自专栏Python小屋

    详解Python GUI版24点游戏制作过程

    \\image\\r1.jpg") #打开图片文件 p1=pImageTk.PhotoImage(im1) #建立与tkinter适用的接口 Label1['image']=p1 #把图片放入标签 \\image\\" + huase[3] + str(shuzi[3]) + ".jpg") p1=pImageTk.PhotoImage(im1) p2=pImageTk.PhotoImage (im2) p3=pImageTk.PhotoImage(im3) p4=pImageTk.PhotoImage(im4) #在标签中设置图片 w.Label1['image'

    2.8K50发布于 2018-04-16
  • 来自专栏python3

    tkinter学习系列(四)之Butto

    ==2.按钮里的图片== (1)只放图片,没有文字 需要先导入图片的路径:img1 = tk.PhotoImage(file="image/01.png") 再使用:image=img1 注:目前支持 == ==案例二== (1)源代码: import tkinter as tk win = tk.Tk() img1 = tk.PhotoImage(file="image/01.png") img2 = tk.PhotoImage(file="image/03.png") img3 = tk.PhotoImage(file="image/04.png") # 300像素大小的图片 button1 ", 对齐方式有:'left', "right", "center" ==案例三== (1)源代码 import tkinter as tk win = tk.Tk() img1 = tk.PhotoImage (file="image/01.png") img2 = tk.PhotoImage(file="image/03.png") img3 = tk.PhotoImage(file="image/04.png

    1.5K30发布于 2020-01-17
  • 来自专栏大家一起学编程

    python-tkinter 实现各种个样的撩妹鼠标拖尾

    white') image1 = Image.open("爱心.jpg") # 打开图片 image = image1.resize((50,60)) # 设置图片大小 photo = ImageTk.PhotoImage # 引入图片 image2 = Image.open("爱心.jpg") image3 = image2.resize((101, 121)) # 设置图片大小 photo1 = ImageTk.PhotoImage 123_" + str(i) + ".PNG") # 打开图片 image = image1.resize((100, 100)) # 设置图片大小 photo = ImageTk.PhotoImage 123_" + str(i) + ".PNG") # 打开图片 image = image1.resize((100, 100)) # 设置图片大小 photo = ImageTk.PhotoImage image1 = Image.open("老婆.png") # 打开图片 image = image1.resize((200, 300)) # 设置图片大小 photo = ImageTk.PhotoImage

    93830发布于 2021-09-18
  • 来自专栏python3

    tkinter -- Label使用图像与文本

    自定义image显示,可以为窗口程序添加一个背景图片 使用PhotoImage类处理图片,只能是gif格式 需要传入一个图片路径 示例: from tkinter import * root = Tk( ) root.title('tkinter') # 使用PhotoImage类处理图片,只能是gif格式 # 需要传入一个图片路径 bm1 = PhotoImage(file='.

    2.4K10发布于 2018-08-02
  • 来自专栏CSDN博客专家-小蓝枣的博客

    Python 图形化界面基础篇:创建工具栏

    # 添加工具按钮 - 打开 open_icon = tk.PhotoImage(file="open.png") # 使用图标文件创建图标对象 toolbar.add_command(image=open_icon , command=open_file, compound="left", label="打开") # 添加工具按钮 # 添加工具按钮 - 保存 save_icon = tk.PhotoImage( (image=save_icon, command=save_file, compound="left", label="保存") # 添加工具按钮 在上述示例中,我们执行以下操作: 使用 tk.PhotoImage =open_file, compound="left", text="打开") open_button.pack(side="left") # 添加工具按钮 - 保存 save_icon = tk.PhotoImage 使用 tk.PhotoImage 创建了两个图标对象,分别代表"打开"和"保存"按钮的图标。请确保在当前工作目录下存在这些图标文件。

    1.6K30编辑于 2023-09-21
  • 来自专栏ZackSock

    Python使用tkinter模块实现推箱子游戏

    3、Painter from tkinter import PhotoImage, NW #在用Canvas绘制图片时,图片必须是全局变量 img = [] class Painter(): white", width=0) # 画墙 elif (j == 1): img.append(PhotoImage ly, anchor=NW, image=img[imgLen - 1]) elif (j == 2): img.append(PhotoImage 对象(PhotoImage对象为tkinter中的对象),PhotoImage对象的创建如下 #通过文件路径创建PhotoImage对象 img = PhotoImage(file="img/img1 在绘制图片时有以下两个步骤:、 #根据数组元素,创建相应的图片对象,添加到列表末尾 img.append(PhotoImage(file="imgs/wall.png")) #在传入图片对象参数时,使用

    3K50发布于 2020-02-14
  • 来自专栏个人编程技术学习与分享

    Python教程4-使用tkinter窗口模块的Label

    StringVar() w = Label(root, textvariable=c) c.set("~新的文本~") w.pack() root.mainloop() 你可以使用 Label 显示 PhotoImage 和 BitmapImage 对象: from tkinter import * root=Tk() photo = PhotoImage(file="D:\zifan\python_logo.PNG"

    1.2K10编辑于 2021-12-14
  • 来自专栏IT 茂茂

    Python的人脸自动戴口罩系统

    /pic/bg.png').resize((1200, 500)) render = ImageTk.PhotoImage(decoration) img = tk.Label(image=render /pic/Mask.png") first_pic = first_pic.resize((60, 60), Image.ANTIALIAS) first_pic = ImageTk.PhotoImage /pic/Mask1.png") second_pic = second_pic.resize((60, 60), Image.ANTIALIAS) second_pic = ImageTk.PhotoImage /pic/Mask3.png") third_pic = third_pic.resize((60, 60), Image.ANTIALIAS) third_pic = ImageTk.PhotoImage /pic/Mask4.png") forth_pic = forth_pic.resize((60, 60), Image.ANTIALIAS) forth_pic = ImageTk.PhotoImage

    88620发布于 2020-03-05
  • 来自专栏sktj

    python tkinter(3) menu 例子

    pulldown = Menu(self.menubar) self.photoObjs = [] for file in photoFiles: img = PhotoImage command=self.greeting).pack(side=LEFT) def makeToolBar(self, size=(40, 40)): from PIL.ImageTk import PhotoImage make new thumb imgobj.thumbnail(size, Image.ANTIALIAS) # best downsize filter img = PhotoImage pulldown = Menu(self.menubar) self.photoObjs = [] for file in photoFiles: img = PhotoImage pulldown = Menu(self.menubar) self.photoObjs = [] for file in photoFiles: img = PhotoImage

    95110编辑于 2022-05-13
领券