-1

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.

  • there is no button. Need to add `click.pack()`. Furthermore, need to point to a function, something like `command = helloCallBack` where `helloCallBack()` is a function. – D.L Apr 11 '22 at 22:47

2 Answers2

0

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.

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
  • Ok. Thank you. By the way, if that's how it is, do you know anything I can use in replace of the activebackground parameter? – Golf Teachers Apr 11 '22 at 21:45
-1

I have added two things to make this work:

  1. a call back function helloCallback
  2. 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.

D.L
  • 4,339
  • 5
  • 22
  • 45