栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

显示方形Tkinter.Button的?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

显示方形Tkinter.Button的?

如果

Button
显示文本,则在使用
height
width
选项时,它们的单位以文本为单位。为了使它们方形,使用像素单位会更好。为此,您需要将该按钮放置在中
frame
,并确保框架不会传播(
grid_propagate
),并允许其子元素填充(
columnconfigure
rowconfigure
)。

这只是一个示例,因为我看不到您的代码。

import Tkinter as tkmaster = tk.Tk()frame = tk.frame(master, width=40, height=40) #their units in pixelsbutton1 = tk.Button(frame, text="btn")frame.grid_propagate(False) #disables resizing of frameframe.columnconfigure(0, weight=1) #enables button to fill frameframe.rowconfigure(0,weight=1) #any positive number would do the trickframe.grid(row=0, column=1) #put frame where the button should bebutton1.grid(sticky="wens") #makes the button expandtk.mainloop()

编辑: 我刚刚看到您的编辑(添加您的代码)。将相同的内容应用于代码后;

import Tkinter, tkFonttop = Tkinter.Tk()right = Tkinter.frame(top)right.pack(side = "right")font = tkFont.Font(family="Helvetica", size=20, weight = tkFont.BOLD)for i in xrange(6):    f = Tkinter.frame(right,width=50,height=50)    b = Tkinter.Button(f, text = str(i), font = font)    f.rowconfigure(0, weight = 1)    f.columnconfigure(0, weight = 1)    f.grid_propagate(0)    f.grid(row = i/3, column = i%3)    b.grid(sticky = "NWSE")top.mainloop()


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/407426.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号