python tkinter button button text is not displayed

1. Problems arise:

There are many kinds of GUI when we use python to write cross-platform,

When using tkinter, when creating a new button, there is a chance that you only see the button but not the text on the button.

btn1 = Button(root,text='关闭',bg="green", fg="blue",command=root.destroy)
btn1.pack()

As shown below:

2. Problem analysis

The same script runs normally under Windows, and the text on the button is visible.

After checking online, some solutions are to use ttk, but the button properties cannot be modified after using ttk, and there is a shadow on the rounded corners of the button.

In fact, this problem is caused by version mismatch. You can check your current tkinter version with the following command:

print("tkinter版本号: ", TkVersion)
print("python版本号: ", sys.version)

My side shows python3.9 and tkinter version 8.5

My mac system defaults to python

Guess you like

Origin blog.csdn.net/streetrust/article/details/124340178