This is my code:
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()
It doesn't return any error to me. But, when I click on the button, nothing happens. Please reply to me as soon as you can.
CodePudding user response:
I don't think the Mac allows you to change the background or activebackground of buttons. Apple wants to control the look of standard controls.
CodePudding user response:
I have added two things to make this work:
- a call back function
helloCallback
- pack the button properly so that it is visable.
here is the code:
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()
result: when the button is pressed, it prints hi there, it works
to the console.