【问题标题】:How to make a Tkinter Text Box have a height of 2 but center the text vertically?如何使 Tkinter 文本框的高度为 2 但垂直居中文本?
【发布时间】:2021-11-10 23:50:20
【问题描述】:

我想让我的 tkinter 文本框的高度为 2,但将文本垂直居中。我曾尝试添加一个 tag_configuration,但它似乎没有奏效。我一直在这个网站上搜索,只找到了水平居中的方法,而不是垂直居中。任何帮助表示赞赏。

        entry = tk.Text(self.frame, height=2, width=20, font=('Corsiva Hebrew', '20'), borderwidth=3,
                             relief='solid')
        entry.tag_configure("center", justify='center')

【问题讨论】:

    标签: python-3.x tkinter


    【解决方案1】:

    您可以将spacing1spacing3 选项设置为某个值(以像素为单位)并改为设置height=1

    下面是一个例子:

    entry = tk.Text(root, height=1, width=20, spacing1=20, spacing3=20,
                    font=('Corsiva Hebrew', '20'), bd=3, relief='solid')
    entry.tag_configure('center', justify='center')
    entry.insert('end', 'Hello World', 'center')
    

    然后输出:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-06-12
      • 2012-06-11
      • 2013-10-15
      • 1970-01-01
      • 2015-03-31
      • 2015-09-16
      相关资源
      最近更新 更多