这是我的代码:
import tkinter as tk
window=tk.Tk()
window.title("Click Me")
click=tk.Button(window, text="Click Me", highlightbackground="blue", activebackground="red")
click.place(x=200,y=300)
window.mainloop()
它不会向我返回任何错误。但是,当我点击按钮时,什么也没发生。请尽快回复我。
我不认为Mac允许您更改按钮的背景或活动背景。苹果希望控制标准控件的外观。
我添加了两件事来实现这一点:
- 一个回调函数
helloCallback
- 把扣子装好,使它好看
这是代码:
import tkinter as tk
window=tk.Tk()
window.title("Click Me")
# a test function to execute when the button is clicked
def helloCallback():
print('hi there, it works')
return
click=tk.Button(window, text="Click Me", highlightbackground="blue", activebackground="red", command=helloCallback)
# pack the button
click.pack()
window.mainloop()
结果:按下按钮时,会将hi there, it works
打印到控制台。