Skip to main content
 首页 » 编程设计

python之Tkinter 按钮在我的 Mac 上不显示文本,尽管代码在其他计算机上有效

2024年12月31日10jyk

我有一个功能代码,除非我单击并按住按钮,否则不会在按钮上显示文本。释放按钮时,文本再次变为空白。我已经尝试在其他论坛上解决这个问题,

please note: THERE IS NOTHING WRONG WITH THE CODE ITSELF.

我的笔记本电脑运行代码的方式存在某种问题。我已经尝试重新安装 python3.7 以及 tcl-tk。我真的不知道还能做什么。

请您参考如下方法:

这是添加此行 from tkinter import ttk 的解决方案。

并且比起使用 ttk. 任何你想使用 Button、Label、Entry 等的地方:

ttk.Button(text="Login", width="30", command = login).pack()

这是代码,您可以尝试一下。

def main_screen(): 
  from tkinter import ttk 
 
  global screen 
  screen = Tk() 
 
  screen.geometry("500x500") 
  screen.title("4rManager") 
 
  Label(text="Login/Register", font=("Calibri", 13)).pack() 
  ttk.Label(text="").pack() 
  ttk.Button(text="Login").pack() 
  ttk.Label(text="").pack() 
  ttk.Button(text="Register").pack() 
 
  screen.mainloop() 
 
main_screen() 

希望我有所帮助。