【Python】解决“Tk_GetPixmap: Error from CreateDIBSection”闪退问题

news2024/10/7 6:42:00

解决Python使用Tkinter的Notebook切换标签时出现的“Tk_GetPixmap: Error from CreateDIBSection 操作成功完成”闪退问题

零、问题描述

在使用Tkinter的Notebook控件时,对其标签进行切换,发现切换不了,一切换就报如下图错误:
“Tk_GetPixmap: Error from CreateDIBSection 操作成功完成”错误截图
第一个页面正常显示,后面的就都不行了,都是报这个错误。第一个页面里面是一些标签(label)、多选框(Checkbutton)、下拉框(Combobox)和按钮(Button),用的都是TTK的库,代码如下:

self.label_in_way = ttk.Label(self.tab_in_setting)
self.label_in_way.place(relx=0.015, rely=0.018, height=21, width=52)
self.label_in_way.configure(text='''输入方式''')

self.cb_in_picture = ttk.Checkbutton(self.tab_in_setting)
self.cb_in_picture.place(relx=0.015, rely=0.073, relwidth=0.071, relheight=0.0, height=23)
self.cb_in_picture.configure(variable=self.cb_in_picture_var)
self.cb_in_picture.configure(text='''图片''')

self.cb_in_video = ttk.Checkbutton(self.tab_in_setting)
self.cb_in_video.place(relx=0.106, rely=0.073, relwidth=0.071, relheight=0.0, height=23)
self.cb_in_video.configure(variable=self.cb_in_video_var)
self.cb_in_video.configure(text='''视频''')

self.cb_in_net = ttk.Checkbutton(self.tab_in_setting)
self.cb_in_net.place(relx=0.197, rely=0.073, relwidth=0.071, relheight=0.0, height=23)
self.cb_in_net.configure(variable=self.cb_in_net_var)
self.cb_in_net.configure(text='''网络''')

self.cb_in_camera = ttk.Checkbutton(self.tab_in_setting)
self.cb_in_camera.place(relx=0.288, rely=0.073, relwidth=0.089, relheight=0.0, height=23)
self.cb_in_camera.configure(variable=self.cb_in_camera_var)
self.cb_in_camera.configure(text='''摄像头''')

self.cb_in_custom = ttk.Checkbutton(self.tab_in_setting)
self.cb_in_custom.place(relx=0.394, rely=0.073, relwidth=0.089, relheight=0.0, height=23)
self.cb_in_custom.configure(variable=self.cb_in_custom_var)
self.cb_in_custom.configure(text='''自定义''')

self.label_in_source = ttk.Label(self.tab_in_setting)
self.label_in_source.place(relx=0.015, rely=0.145, height=21, width=52)
self.label_in_source.configure(text='''输入来源''')

self.cb_in_source = ttk.Combobox(self.tab_in_setting)
self.cb_in_source.place(relx=0.015, rely=0.2, relheight=0.042, relwidth=0.964)
self.cb_in_source.configure(textvariable=self.cb_in_source_var)

self.btn_in_source_choose = ttk.Button(self.tab_in_setting)
self.btn_in_source_choose.place(relx=0.848, rely=0.255, height=27, width=87)
self.btn_in_source_choose.configure(text='''选择''')

第一个页面

第二个页面页差不多是这些东西,多选框换成了输入框(Entry)而已,代码如下:

self.label_save_type = ttk.Label(self.tab_out_setting)
self.label_save_type.place(relx=10.0, rely=10.0, height=21, width=52)
self.label_save_type.configure(text='''保存类型''')

self.cb_prediction_info = ttk.Checkbutton(self.tab_out_setting)
self.cb_prediction_info.place(relx=10.0, rely=40.0, relwidth=71.0, relheight=0.0, height=23)
self.cb_prediction_info.configure(variable=self.cb_prediction_info_var)
self.cb_prediction_info.configure(text='''预测信息''')

self.cb_prediction_video = ttk.Checkbutton(self.tab_out_setting)
self.cb_prediction_video.place(relx=100.0, rely=40.0, relwidth=71.0, relheight=0.0, height=23)
self.cb_prediction_video.configure(variable=self.cb_prediction_video_var)
self.cb_prediction_video.configure(text='''预测视频''')

self.cb_raw_video = ttk.Checkbutton(self.tab_out_setting)
self.cb_raw_video.place(relx=200.0, rely=40.0, relwidth=71.0, relheight=0.0, height=23)
self.cb_raw_video.configure(variable=self.cb_raw_video_var)
self.cb_raw_video.configure(text='''原始视频''')

self.label_save_path = ttk.Label(self.tab_out_setting)
self.label_save_path.place(relx=10.0, rely=80.0, height=21, width=52)
self.label_save_path.configure(text='''保存位置''')

self.entry_path = ttk.Entry(self.tab_out_setting)
self.entry_path.place(relx=10.0, rely=110.0, relheight=23.0, relwidth=636.0)

self.btn_choose_save_path = ttk.Button(self.tab_out_setting)
self.btn_choose_save_path.place(relx=560.0, rely=140.0, height=27, width=87)
self.btn_choose_save_path.configure(text='''选择''')

第二个页面
到某度上查不到啥资料,只能自己解决,折腾了半天,碰巧发现了解决方案。

壹、解决问题

我做了如下尝试:

  1. 把页面二的所有控件清空,切换到页面二,不报错
  2. 页面二只留下标签(Label),不报错,也不显示
  3. 页面二只留下多选框(Checkbutton),也不报错,不显示
  4. 页面二只留下输入框(Entry),报错
  5. 页面二只留下按钮(Button),不报错,也不显示
  6. 页面二只删除输入框(Entry),不报错,也不显示

得出是输入框造成报错的结论,但是不显示是怎么回事呢?不知道

第一次尝试

简单分析页面一和页面二的情况,其他控件都一样,就输入框(Entry)和下拉框(Combobox)不一样,其中,下拉框设置了textvariable属性,输入框则没有,而下拉框是可以正常使用的,所以怀疑是textvariable属性的问题。

给输入框加上textvariable属性:

self.entry_path_var = tk.StringVar()  # 创建值
self.entry_path = ttk.Entry(self.tab_out_setting)
self.entry_path.place(relx=10.0, rely=110.0, relheight=23.0, relwidth=636.0)
self.entry_path.configure(textvariable=self.entry_path_var)  # 设置值

还是报错。

第二次尝试

在刚刚的尝试中有一个现象,不报错也不显示,有没有一种可能,它不是不显示,只是显示到屏幕外边去了?

这边给它设置位置的就是place函数了,简单查了下它的用法,其中比较重要的:

relx=amount - locate anchor of this widget between 0.0 and 1.0 relative to width of master (1.0 is right edge)
relx的作用是指定相对坐标,relx的取值为0~1的小数。如果relx=0,表示子控件的x方向的起始位置在父控件的最左边;如果rely=1,表示子控件的y方向的起始位置在父控件的最右边。

然后看了下我的代码,relxrelyrelheightrelwidth全都大于1了,可能是这个的问题。

重新改代码如下(尝试了一个控件,通过了,然后把一页的改了):

self.label_save_type = ttk.Label(self.tab_out_setting)
self.label_save_type.place(relx=0.015, rely=0.018, height=21, width=52)
self.label_save_type.configure(text='''保存类型''')

self.cb_prediction_info = ttk.Checkbutton(self.tab_out_setting)
self.cb_prediction_info.place(relx=0.015, rely=0.073, relwidth=0.108, relheight=0.0, height=23)
self.cb_prediction_info.configure(variable=self.cb_prediction_info_var)
self.cb_prediction_info.configure(text='''预测信息''')

self.cb_prediction_video = ttk.Checkbutton(self.tab_out_setting)
self.cb_prediction_video.place(relx=0.152, rely=0.073, relwidth=0.108, relheight=0.0, height=23)
self.cb_prediction_video.configure(variable=self.cb_prediction_video_var)
self.cb_prediction_video.configure(text='''预测视频''')

self.cb_raw_video = ttk.Checkbutton(self.tab_out_setting)
self.cb_raw_video.place(relx=0.303, rely=0.073, relwidth=0.108, relheight=0.0, height=23)
self.cb_raw_video.configure(variable=self.cb_raw_video_var)
self.cb_raw_video.configure(text='''原始视频''')

self.label_save_path = ttk.Label(self.tab_out_setting)
self.label_save_path.place(relx=0.015, rely=0.145, height=21, width=52)
self.label_save_path.configure(text='''保存位置''')

self.entry_path = ttk.Entry(self.tab_out_setting)
self.entry_path.place(relx=0.015, rely=0.2, relheight=0.042, relwidth=0.964)

self.btn_choose_save_path = ttk.Button(self.tab_out_setting)
self.btn_choose_save_path.place(relx=0.848, rely=0.255, height=27, width=87)
self.btn_choose_save_path.configure(text='''选择''')

一切正常!

贰、总结

至此,问题解决,是调用place函数时传入的参数不正确造成的,rel(relative)开头的参数一般传入值的区间应该是[0,1],改过就好了。我的代码是使用Page 7.6生成的,故没有多管它调用每个函数的细节。本次错误应该算是page 7.6的一个Bug。

叁、参考文献

  1. 记录一个没解决的createDIBSection失败的bug
  2. CreateDIBSection函数详解
  3. tkinter-place布局详解
  4. Python之tkinter 多选项卡 Notebook

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/882471.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Python学习笔记_基础篇(五)_数据类型之字典

一.基本数据类型 整数:int 字符串:str(注:\t等于一个tab键) 布尔值: bool 列表:list 列表用[] 元祖:tuple 元祖用() 字典:dict 注:所有的数据类型都存在想对…

3. 爬取自己CSDN博客列表(分页查询)(网站反爬虫策略,需要在代码中添加合适的请求头User-Agent,否则response返回空)

文章目录 步骤打开谷歌浏览器输入网址按F12进入调试界面点击网络,清除历史消息按F5刷新页面找到接口(community/home-api/v1/get-business-list)接口解读 撰写代码获取博客列表先明确返回信息格式json字段解读 Apipost测试接口编写python代码…

每天一道leetcode:646. 最长数对链(动态规划中等)

今日份题目&#xff1a; 给你一个由 n 个数对组成的数对数组 pairs &#xff0c;其中 pairs[i] [lefti, righti] 且 lefti < righti 。 现在&#xff0c;我们定义一种 跟随 关系&#xff0c;当且仅当 b < c 时&#xff0c;数对 p2 [c, d] 才可以跟在 p1 [a, b] 后面…

JMeter 特殊组件-逻辑控制器与BeanShell PreProcessor 使用示例

文章目录 前言JMeter 特殊组件-逻辑控制器与BeanShell PreProcessor 使用示例1. 逻辑控制器使用1.1. While Controller 使用示例1.2. 如果&#xff08;If&#xff09;控制器 使用示例 2. BeanShell PreProcessor 使用示例 前言 如果您觉得有用的话&#xff0c;记得给博主点个赞…

视频云存储平台EasyCVR视频汇聚接入AI算法接口,如何在检测中对视频流画框?

视频集中存储EasyCVR安防监控视频汇聚平台基于云边端智能协同架构&#xff0c;具有强大的数据接入、处理及分发能力&#xff0c;平台可支持多协议接入&#xff0c;包括市场主流标准协议与厂家私有协议及SDK&#xff0c;如&#xff1a;国标GB28181、RTMP、RTSP/Onvif、海康Ehome…

Matlab中图例的位置(图例放在图的上方、下方、左方、右方、图外面)等

一、图例默认位置 默认的位置在NorthEast r 10; a 0; b 0; t0:0.1:2.1*pi; xar*cos(t); ybr*sin(t); A1plot(x,y,r,linewidth,4);%圆 hold on axis equal A2plot([0 0],[1 10],b,linewidth,4);%直线 legend([A1,A2],圆形,line)二、通过Location对legend的位置进行改变 变…

国标GB28181视频平台EasyGBS国标视频平台接入大量通道,创建角色未响应的问题解决方案

国标GB28181协议视频平台EasyGBS是基于国标GB28181协议的视频云服务平台&#xff0c;支持多路设备同时接入&#xff0c;并对多平台、多终端分发出RTSP、RTMP、FLV、HLS、WebRTC等格式的视频流。平台可提供视频监控直播、云端录像、云存储、检索回放、智能告警、语音对讲、平台级…

生成IOS app专用密码教程

转载&#xff1a;生成IOS app专用密码教程 APP专用密码app-specific password是专门用于上传ipa文件的一种密码&#xff0c;是一种苹果的安全机制&#xff01; 现在苹果开发者账号开启了双重认证&#xff0c;提交ipa文件时候都需要这个密码&#xff01; 一.注册AppID账号 1…

Linux 路由三大件

对于 Linux 网络&#xff0c;好奇心强的同学一定思考过两个问题&#xff1a; 当我们发出一个包的时候&#xff0c;Linux 是如何决策该从哪个网卡&#xff08;假设有多个网卡&#xff09;、哪个下一跳发出这个包&#xff0c;用什么 IP 作为 source......当 Linux 收到一个包时&a…

云服务 Ubuntu 20.04 版本 使用 Nginx 部署静态网页

所需操作&#xff1a; 1.安装Nginx 2.修改配置文件 3.测试、重启 Nginx 4.内部修改防火墙 5.配置解析 6.测试是否部署成功 1.安装Nginx // 未使用 root 账号 apt-get update // 更新apt-get install nginx // 安装 nginx 1.1.测试是否安装没问题 在网页上输入云服务的公网…

链表之第一回

欢迎来到我的&#xff1a;世界 收录专栏&#xff1a;链表 希望作者的文章对你有所帮助&#xff0c;有不足的地方还请指正&#xff0c;大家一起学习交流 ! 目录 前言第一题&#xff1a;删除链表的倒数第n个节点第二题&#xff1a;链表的中间结点第三题&#xff1a;合并两个排序…

Apache Dubbo 云原生可观测性的探索与实践

作者&#xff1a;宋小生 - 平安壹钱包中间件资深工程师 Dubbo3 可观测能力速览 Apache Dubbo3 在云原生可观测性方面完成重磅升级&#xff0c;使用 Dubbo3 最新版本&#xff0c;你只需要引入 dubbo-spring-boot-observability-starter 依赖&#xff0c;微服务集群即原生具备以…

Gradio部署应用到服务器不能正常访问

用Gradio部署一个基于ChatGLM-6B的应用&#xff0c;发布到团队的服务器上&#xff08;局域网&#xff0c;公网不能访问&#xff09;&#xff0c;我将gradio应用发布到服务器的9001端口 import gradio as gr with gr.Blocks() as demo:......demo.queue().launch(server_port90…

视频集中存储安防监控平台EasyCVR优化AI硬件接入时的通道显示异常问题

安防视频监控平台视频集中存储EasyCVR可拓展性强、视频能力灵活、部署轻快&#xff0c;可支持的主流标准协议有国标GB28181、RTSP/Onvif、RTMP等&#xff0c;以及支持厂家私有协议与SDK接入&#xff0c;包括海康Ehome、海大宇等设备的SDK等。 安防监控视频云存储平台EasyCVR既具…

NPCon2023 AI模型技术与应用峰会:参后感

8月12日&#xff0c;参加了在北京皇家格兰云天大酒店召开的“全链路搭建人工智能研发基础”会议。此次会议汇集了众多人工智能领域的顶尖技术专家&#xff0c;他们就人工智能基础设施、计算能力资源以及模型训练等核心议题展开了深入的研讨。 1.主题以及收获 主题1.由千芯科技…

网络编程555

上传代码 #include <stdio.h>//客户端 #include <string.h> #include <stdlib.h> #include<sys/types.h> #include<sys/socket.h> #include<arpa/inet.h> #include<head.h> #define PORT 69 #define IP "192.168.124.57"…

Arduino之TFT_eSPI驱动彩色LCD屏

一、TFT_eSPI库简介 1.1 安装TFT_eSPI库 在User_Setup.h中进行个人屏幕参数的配置&#xff1a; User_Setup.hTFT驱动板备注TFT_MISO无 TFT_MOSISDA TFT_SCLKCLK TFT_CSCS液晶屏片选信号&#xff0c;低电平使能TFT_DCRS液晶屏寄存器/数据选择信号TFT_RSTRST液晶屏复位信号TF…

通达信一目均衡表指标选股公式,又称云图指标

一目均衡表&#xff08;Ichimoku Kinko Hyo&#xff0c;又称一目均衡图、云图指标&#xff09;是由日本记者兼股市专家一目山人发明的&#xff0c;被广泛用于股票、外汇、期货等金融市场的趋势分析和支撑阻力位的判断。一目均衡表提供了一种综合性的视角&#xff0c;结合了多个…

LC-相交链表(解法1)

LC-相交链表&#xff08;解法1&#xff09; 链接&#xff1a;https://leetcode.cn/problems/intersection-of-two-linked-lists/description/ 描述&#xff1a;给你两个单链表的头节点 headA 和 headB &#xff0c;请你找出并返回两个单链表相交的起始节点。如果两个链表不存在…

Linux交叉编译opencv并移植ARM端

Linux交叉编译opencv并移植ARM端 - 知乎 一、安装交叉编译器 目标平台为arm7l&#xff0c;此为32位ARM架构&#xff0c;要安装合适的编译器 sudo apt install arm-linux-gnueabihf-gcc sudo apt install arm-linux-gnueabihf-g注意&#xff1a;64位ARM架构的编译器与32位ARM架…