为什么我的 Button 小部件不能垂直展开 [英] Why won't my Button widget expand vertically

查看:31
本文介绍了为什么我的 Button 小部件不能垂直展开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在熟悉 Tkinter,我正在尝试编写一个非常简单的程序,该程序使用包几何管理器在窗口中显示一个按钮.

I am familiarizing myself with Tkinter, and I am attempting to write a very simple program, which displays a button in a window, using the pack geometry manager.

我正在试验 pack() 的各种配置选项,例如 expandfillside>,我遇到了一个奇怪的问题.我写了以下代码:

I was experimenting with various configuration options for pack(), such as expand, fill, and side, and I've run into a peculiar problem. I have written the following code:

from Tkinter import *

root = Tk()
widget = Button(root, text='text')
widget.pack(expand=YES, fill=BOTH)
root.mainloop()

问题是按钮在水平方向扩展以填充窗口,而不是垂直方向.这与我使用 fill=X 而不是指定 fill=BOTH 时得到的结果相同.此外,如果我改为指定 fill=Y 按钮不会在任一方向扩展.垂直方向的填充似乎出了点问题,我无法弄清楚它可能是什么.

The problem is that the button expands to fill the window in the horizontal direction, but not the vertical direction. This is the same result that I get if instead of specifying fill=BOTH I use fill=X. In addition, if I specify instead fill=Y the button does not expand in either direction. Something seems to be going wrong with the fill in the vertical direction, and I cannot figure out what it might be.

我尝试在 Google 上搜索此问题,但出人意料地发现其他任何人都没有提到这种情况.我正在使用带有 OS X Yosemite 并运行 python 2.7.5 的 Mac.我也尝试使用 python 3.4.1 进行编译,但没有看到任何变化.

I attempted to Google this problem and surprisingly found no mention of this happening to anyone else. I am using a Mac with OS X Yosemite and running python 2.7.5. I also attempted to compile with python 3.4.1 and saw no change.

根据下面的答案和评论,很明显我的代码没有任何问题,因为它似乎可以在其他机器上运行.如果不是代码中的错误,有谁知道当我运行上述代码时可能导致按钮无法垂直拉伸的原因是什么?

Based off of the answer and comments below, it is clear that there is nothing wrong with my code, because it seems to work on other machines. If not an error in the code, does anyone know what could possibly be causing the button to not stretch vertically when I run the above code?

推荐答案

这是 OSX 上本机按钮的一项功能.OSX 上的按钮将是固定高度,不会垂直扩展.除了使用不同的小部件(例如标签)之外,您无能为力.

This is a feature of native buttons on OSX. Buttons on OSX will be a fixed height and will not expand vertically. There is nothing you can do, short of using a different widget such as a label.

这篇关于为什么我的 Button 小部件不能垂直展开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆