Учусь beeware. Запускаю проект с кодом из документации. Вот app.py
spoilerimport toga
from toga.style import Pack
from toga.style.pack import COLUMN, ROW
class Primenumberscalculator(toga.App):
def startup(self):
main_box = toga.Box(style=Pack(direction=COLUMN))
name_label = toga.Label(
'Your name: ',
style=Pack(padding=(0, 5))
)
self.name_input = toga.TextInput(style=Pack(flex=1))
name_box = toga.Box(style=Pack(direction=ROW, padding=5))
name_box.add(name_label)
name_box.add(self.name_input)
button = toga.Button(
'Say Hello!',
on_press=self.say_hello,
style=Pack(padding=5)
)
main_box.add(name_box)
main_box.add(button)
self.main_window = toga.MainWindow(title=self.formal_name)
self.main_window.content = main_box
self.main_window.show()
def say_hello(self, widget):
print("Hello", self.name_input.value)
def main():
return Primenumberscalculator()
Всё работает. Исправил на следующий код app.py
spoilerimport toga
from toga.style import Pack
from toga.style.pack import COLUMN, ROW
class Primenumberscalculator(toga.App):
def startup(self):
box1 = toga.Box()
box2 = toga.Box()
box3 = toga.Box()
box4 = toga.Box()
box5 = toga.Box()
box6 = toga.Box()
mainBox = toga.Box()
self.inputText = toga.TextInput()
self.inputText.style.width = 300
#
btn7 = toga.Button('7')
btn7.style.padding_top = 20
btn8 = toga.Button('8')
btn8.style.padding_top = 20
btn9 = toga.Button('9')
btn9.style.padding_top = 20
btnPlus = toga.Button('+')
btnPlus.style.padding_top = 20
#
btn4 = toga.Button('4')
btn5 = toga.Button('5')
btn6 = toga.Button('6')
btnMinus = toga.Button('-')
#
btn1 = toga.Button('1')
btn2 = toga.Button('2')
btn3 = toga.Button('3')
btnMultiply = toga.Button('*')
#
btnDot = toga.Button('.')
btn0 = toga.Button('0')
btnClear = toga.Button('C')
btnDivide = toga.Button('/')
#
btnCalculate = toga.Button('Calculate')
btnCalculate.style.width = 300
btnCalculate.style.padding_top = 30
#
box1.add(self.inputText)
#
box2.add(btn7)
box2.add(btn8)
box2.add(btn9)
box2.add(btnPlus)
#
box3.add(btn4)
box3.add(btn5)
box3.add(btn6)
box3.add(btnMinus)
#
box4.add(btn1)
box4.add(btn2)
box4.add(btn3)
box4.add(btnMultiply)
#
box5.add(btnDot)
box5.add(btn0)
box5.add(btnClear)
box5.add(btnDivide)
#
box6.add(btnCalculate)
#
mainBox.add(box1)
mainBox.add(box2)
mainBox.add(box3)
mainBox.add(box4)
mainBox.add(box5)
mainBox.add(box6)
mainBox.style.update(direction=COLUMN)
self.mainWin = toga.MainWindow(title='Prime numbers calculator')
self.mainWin.content = mainBox
self.mainWin.show()
def main():
return Primenumberscalculator()
Не запускается
Traceback (most recent call last):
File "c:\users\maxim\beeware\beeware-venv\lib\site-packages\toga_winforms\app.py", line 155, in run_app
self.create()
File "c:\users\maxim\beeware\beeware-venv\lib\site-packages\toga_winforms\app.py", line 74, in create
self.create_menus()
File "c:\users\maxim\beeware\beeware-venv\lib\site-packages\toga_winforms\app.py", line 108, in create_menus
self.interface.main_window._impl.native.Controls.Add(menubar)
AttributeError: 'NoneType' object has no attribute '_impl'