0

I have a clickable qt button:

window.my_button.clicked.connect(functools.partial(print, "Clicked!"))

I'd expect this to print Clicked!\n to console when I press the button. Instead it prints Clicked! False\n.

Why does it do this and how do I change it to the expected behavior?

Valentin Metz
  • 393
  • 6
  • 13
  • 1
    This is explained in the [`partial` documentation](https://docs.python.org/3/library/functools.html#functools.partial): "If more arguments are supplied to the call, they are appended to args." Since `print()` accepts any number of arguments, there's where you get that further value; as you can see from the docs about the [`clicked`](https://doc.qt.io/qt-5/qabstractbutton.html#clicked) signal, it **always** has a `checked` argument (which is used for checkable buttons). If you want to ignore that, use a lambda or a wrapper (with proper keyword arguments if any is needed). – musicamante Oct 14 '22 at 03:18
  • Since the lambda worked well, I'll leave this example here, should anyone stumble upon the issue in the future: `window.start_camera_button.clicked.connect(lambda: print("Clicked!"))` – Valentin Metz Oct 14 '22 at 11:43

0 Answers0