python C tkinter中的标签宽度
发布时间:2023-12-17 05:17:35 所属栏目:Python 来源:DaWei
导读: 我正在用tkinter编写一个应用程序,我试图在框架中放置几个标签……不幸的是,windowTitle=Label(... width=100)
和
windowFrame=Frame(... width=100)
宽度差异很大……
到目前为
和
windowFrame=Frame(... width=100)
宽度差异很大……
到目前为
我正在用tkinter编写一个应用程序,我试图在框架中放置几个标签……不幸的是,windowTitle=Label(... width=100) 和 windowFrame=Frame(... width=100)宽度差异很大…… 到目前为止,我使用此代码: windowFrame=Frame(root,borderwidth=3,relief=SOLID,width=xres/2,height=yres/2) windowFrame.place(x=xres/2-160,y=yres/2-80) windowTitle=Label(windowFrame,background="#ffa0a0",text=title) windowTitle.place(x=0,y=0) windowContent=Label(windowFrame,text=content,justify="left") windowContent.place(x=8,y=32) ... #xres is screen width #yres is screen height由于某种原因,设置标签宽度没有正确设置宽度,或者不使用像素作为测量单位…那么,有没有办法以适应框架长度的方式放置windowTitle小部件,或者以像素为单位设置标签宽度? 解决方法 高度和宽度在包含文本时以文本单位定义标签的大小.按照@Elchonon Edelson的建议,设置第一帧小技巧的大小: from tkinter import * root = Tk() def make_label(master,x,y,h,w,*args,**kwargs): f = Frame(master,height=h,width=w) f.pack_propagate(0) # don't shrink f.place(x=x,y=y) label = Label(f,**kwargs) label.pack(fill=BOTH,expand=1) return label make_label(root,10,40,text='xxx',background='red') make_label(root,30,background='blue') root.mainloop() (编辑:台州站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- Django:如何在内联formset中显示每个模型对象的表单错误
- python – 在字符串列表中标记动态子字符串
- python – plotly.offline.iplot给出一个大的空白字段作为输
- 举例详解Python中的split()函数的使用方法
- Python C NameError:未定义名称itemgetter
- python – django:将每个用户数据分开
- 如何使用Python的ctypes和readinto读取包含数组的结构?
- python C 方法中的单个字符串或字符串列表
- python – 使用scikit-learn(sklearn),如何处理线性回归的缺
- python – PEP 8和列表理解
推荐文章
站长推荐
- 具有distinct()的Django order_by()过滤器
- python – 什么是django.utils.functional .__ p
- python – Mac OS上“import cv”期间的“分段错
- python – TypeError:JSON对象必须是str,而不是
- python C Django C 模板显示模型verbose_namesob
- 在Python中开发时保护MySQL密码?
- python C hashlib.md5()TypeError:Unicode对象必
- python – 通过没有循环的2D索引数组索引2D nump
- django – 在Bootstrap中激活点击的选项卡
- python – 为Matplotlib imshow()手动定义的轴标