您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

python – tkinter中的标签宽度

5b51 2022/1/14 8:22:34 python 字数 1760 阅读 548 来源 www.jb51.cc/python

我正在用tkinter编写一个应用程序,我试图在框架中放置几个??标签……不幸的是, windowTitle=Label(... width=100) 和 windowFrame=Frame(... width=100) 宽度差异很大…… 到目前为止,我使用此代码: windowFrame=Frame(root,borderwidth=3,relief=SOLID,width=xres/2,hei

概述

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小部件,或者以像素为单位设置标签宽度?

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()

总结

以上是编程之家为你收集整理的python – tkinter中的标签宽度全部内容,希望文章能够帮你解决python – tkinter中的标签宽度所遇到的程序开发问题。


如果您也喜欢它,动动您的小指点个赞吧

除非注明,文章均由 laddyq.com 整理发布,欢迎转载。

转载请注明:
链接:http://laddyq.com
来源:laddyq.com
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。


联系我
置顶