AttributeError: привязка отсутствует - PullRequest
0 голосов
/ 12 июня 2018

Я пытаюсь создать кнопку с модулем vpython (а не tkinter по некоторым причинам), и у меня появляется эта ошибка: AttributeError: отсутствует привязка

Что такое привязка и как я могу это исправить?

from vpython import *
def change(): # Appelé par controls quand on clique sur le bouton
    if b.text == 'Click me':
        b.text = 'Try again'
    else:
        b.text = 'Click me'

c = controls() # Crée une fenêtre pour les contrôles
# Crée un bouton dans la fenêtre des contrôles:
b = button( pos=(0,0), width=60, height=60, 
          text='Click me', action=lambda: change() )
while 1:
    c.interact()

1 Ответ

0 голосов
/ 14 июня 2018

Из следующего примера

https://github.com/BruceSherwood/vpython-jupyter/blob/master/Demos/ButtonsSlidersMenus2.ipynb

Есть строка

cbutton = button (text = ' Red ', textcolor =color.red, background = color.cyan, pos = scene.title_anchor, bind = Color)

, поэтому похоже, что вам нужно добавить атрибут bind для вашей кнопки.

b = button (pos = (0,0), ширина = 60, высота = 60, текст = 'Click me', action = lambda: change (), bind = change)

Из документации о кнопках и виджетах в VPython7.

http://www.glowscript.org/docs/VPythonDocs/controls.html

говорит, что атрибут связывания для кнопки -

"bind Имя функции, вызываемой при нажатии кнопки. Не может быть измененопосле создания кнопки. "

...