带有换行符的按钮在Mac OS X上无法正常显示

时间:2023-01-26 16:44:24

This code works fine in Windows. On Mac OS X it only shows "Multiple" in the button and everything past the newline gets wiped out. I'm running Python 2.6.5 on Mac.

此代码在Windows中正常工作。在Mac OS X上,它只在按钮中显示“Multiple”,并且新行之后的所有内容都将被删除。我在Mac上运行Python 2.6.5。

import Tkinter as tk
class App:
    def __init__(self, master):
        self.a_button = tk.Button(master, text="Multiple\nLines\nOf Text")
        self.a_button.pack()

ROOT = tk.Tk()
APP = App(ROOT)
ROOT.mainloop()

1 个解决方案

#1


4  

Mac native pushbuttons don't let you do that; they have 3 predefined heights for the various control sizes and that's it. Other button styles do support arbitrary dimensions; one option is to use a Tile button instead:

Mac原生按钮不允许你这样做;对于各种控制尺寸,它们有3个预定义的高度,就是这样。其他按钮样式确实支持任意尺寸;一个选项是使用Tile按钮代替:

    self.a_button = tk.Widget(master, 'ttk::button',
                              dict(text="Multiple\nLines\nOf Text"))

#1


4  

Mac native pushbuttons don't let you do that; they have 3 predefined heights for the various control sizes and that's it. Other button styles do support arbitrary dimensions; one option is to use a Tile button instead:

Mac原生按钮不允许你这样做;对于各种控制尺寸,它们有3个预定义的高度,就是这样。其他按钮样式确实支持任意尺寸;一个选项是使用Tile按钮代替:

    self.a_button = tk.Widget(master, 'ttk::button',
                              dict(text="Multiple\nLines\nOf Text"))