-1

I'm using Python 2.7.13 with Tkinter.

This is part of my program:

PAButton = Tkinter.ButtonPress(PAFrame, text='PA', fg='white', bg='blue')
PAButton.pack()
self.PAButton.bind("<ButtonPress>", self.playPA)


This is the gist of what I am trying to do:

When PAButton is pressed (not released), run the function playPA() as defined earlier in the script.


However, I get this error:
AttributeError: 'module' object has no attribute 'ButtonPress'


How would I correctly accomplish my goal?

user604803
  • 33
  • 1
  • 9
  • 1
    ... please, do research. – S.G. Harmonia Jul 16 '17 at 23:42
  • 1
    Are you sure that `Tkinter` has a `ButtonPress` method, but I didn't find it. – ksai Jul 16 '17 at 23:45
  • @S.G.Harmonia I did. I found [this] (https://stackoverflow.com/questions/34522095/gui-button-hold-down) and [this] (https://stackoverflow.com/questions/16548757/how-can-i-identify-when-a-button-is-released-in-tkinter) and I based my code off of that. Please, don't comment rashly. – user604803 Jul 17 '17 at 00:11

1 Answers1

1

There's no such thing as ButtonPress. It's Button.

EDIT: For the .bind() function, instead of "<ButtonPress>", use "<Button-1>".

S.G. Harmonia
  • 297
  • 2
  • 18
  • However, the command only occurs when the button is released. How could I run a command when the button is pressed? – user604803 Jul 17 '17 at 00:11
  • Using your edit, I had to write `playPA()` like this: `PAButton.bind("", playPA())` because I got an error: `TypeError: playPA() takes no arguments (1 given)`. However, when I run the program now, the playPA() function occurs before the GUI starts and nothing happens when I press the PAButton. – user604803 Jul 17 '17 at 00:30
  • In a func bind using `bind()`, you are not supposed to add `()` to the end of the func name. Also, if you haven't already, add `event` to the arguments of your function. – S.G. Harmonia Jul 17 '17 at 01:31
  • This solved the issue. Thank you! – user604803 Jul 17 '17 at 01:48