Python Tkinter按钮文本不可见

时间:2019-11-23 08:54:35

标签: python macos button tkinter

我试图显示2个按钮,但是除非按住该按钮,否则按钮上的文本不可见。

This is the image of the loaded window

This is the image of the window when I hold down the button

只有按下按钮,我才能查看文本。

代码:

from tkinter import *

class App:
   def __init__(self,master):
      frame = Frame(master)
      frame.pack()

      self.mb = Button(frame,
                       text = "XYZ",
                       command = self.button_click)
      self.tb = Button(frame,
                       text="ABC",
                       command=self.button_click)
      self.mb.pack(expand = 1, fill = BOTH)
      self.tb.pack(expand=1, fill=BOTH)
      frame.mainloop()


   def button_click(self):
      print("button was clicked")

def main():
   root = Tk()
   app = App(root)

if __name__ == "__main__":
   main()

如何解决此问题,使其正常工作(即使不单击按钮,按钮上的文本也会显示出来)?

我正在运行macOS Catalina和Python 3.7.4

1 个答案:

答案 0 :(得分:0)

我解决了。但我不确定。您可以导入 ttk 并更改按钮的名称。

from tkinter import *
from tkinter import ttk

self.mb = ttk.Button(........)

self.tb = ttk.Button(........)