python - 插入图像后标签的大小发生变化
问题描述
我正在尝试通过将这些部分整齐地添加到垂直排序的 6 个标签中来重建分为 6 个部分的图片。图片具有带有标签的确切尺寸,但在添加它们之后,标签仍然变小,或者图像没有达到它们应有的大小,因此图片部分没有结合。为了证明这一点,我在使用我制作的功能添加图像之前和之后检查了标签的大小。
带有图像、大小和结果的标签代码:
Lwidth = 512 #root.winfo_width()
Lheight = 115 #root.winfo_height() // 6
img1=Image.open('row-1.png')
bg1=ImageTk.PhotoImage(img1)
l1 = Label(root, image=bg1)
l1.pack(fill='both', expand=True)
l1.image = bg1
l1.update()
img2=Image.open('row-2.png')
bg2=ImageTk.PhotoImage(img2)
l2 = Label(root, image=bg2)
l2.pack(fill='both', expand=True)
l2.image = bg2
l2.update()
img3=Image.open('row-3.png')
bg3=ImageTk.PhotoImage(img3)
l3 = Label(root, image=bg3)
l3.pack(fill='both', expand=True)
l3.image = bg3
l3.update()
img4=Image.open('row-4.png')
bg4=ImageTk.PhotoImage(img4)
l4 = Label(root, image=bg4)
l4.pack(fill='both', expand=True)
l4.image = bg4
l4.update()
img5=Image.open('row-5.png')
bg5=ImageTk.PhotoImage(img5)
l5 = Label(root, image=bg5)
l5.pack(fill='both', expand=True)
l5.image = bg5
l5.update()
img6=Image.open('row-6.png')
bg6=ImageTk.PhotoImage(img6)
l6 = Label(root, image=bg6)
l6.pack(fill='both', expand=True)
l6.image = bg6
l6.update()
root.update()
结果:
这就是我从没有图像的代码中创建的函数中得到的:
我完全确定问题不在于图像,我尝试了许多不同的方法来确保它们被正确分割,而不会丢失某些部分......
解决方案
推荐阅读
- java - 正则表达式中的通配符仅在停止词之前是贪婪的
- typescript - 确保静态键存在于另一个类上
- r - R shinydashboardplus 翻转框 - 如何删除图像
- javascript - 提取库到单独的文件
- ios - Xamarion.iOS statusBar BackgroundColor 不会改变
- r - install.packages("knitr") 导致错误 untar2: 文件上的不完整块和包 'knitr' 的安装具有非零退出状态
- c - 使用结构变量时链表中的问题
- javascript - 在 github 页面中托管 Angular SSR
- java - Hygieia Jenkins-Build Collector 不以 UnsatisfiedDependencyException 开头
- extract - 在名称未知的文件中查找数值序列的一部分