【问题标题】:Tkinter Button text invisible until window resizeTkinter 按钮文本在窗口调整大小之前不可见
【发布时间】:2019-02-02 00:14:35
【问题描述】:

我有 Python 3.6.3。我正在尝试使用提交和退出按钮编写一个简单的 GUI 应用程序。我有这个 GUI 代码:

from tkinter import *
from sys import exit

...

some = True
stuff = False
here = "bar"

top = Tk()

submitButton = Button(top, text="Submit", command=lambda: submit(some, things, set, here)).pack(pady=50, side=LEFT)
exitButton = Button(top, text="Quit", command=exit).pack(pady=50, side=RIGHT)

top.mainloop()

但是,在运行此代码后,我的按钮标签是不可见的:

为了再次看到它们,我需要调整窗口大小,哪怕只是一点点:

我在这里做错了什么,或者这是 tkinter 的错误?

【问题讨论】:

  • 它是否使用默认填充 (0) 执行此操作?
  • 无法重现,gui 显示正确(OSX)
  • 顺便说一句,.pack 返回None,因此您实际上并未将 Button 小部件绑定到这些名称。
  • 在 ubuntu 上为我工作
  • @TheoC 你是怎么解决的?

标签: python python-3.x button tkinter


【解决方案1】:

在您的 mainloop 调用之前添加一个更新调用。

top.update()
top.mainloop()

还可以考虑升级到 python3.7,因为 Mac 的很多 tkinter 问题在 3.7 中已修复。

【讨论】:

  • 这没有用,我在它之前添加了top.update(),但没有改变。
猜你喜欢
  • 1970-01-01
  • 2017-11-18
  • 1970-01-01
  • 1970-01-01
  • 2021-09-20
  • 1970-01-01
  • 2015-04-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多