概述
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中的标签宽度所遇到的程序开发问题。
如果您也喜欢它,动动您的小指点个赞吧