Answer the question
In order to leave comments, you need to log in
Def does not accept more than two arguments, what is the reason and how to fix it (python kivy)?
When entering text in textinput and clicking on plusbtn, in theory, a button with the entered text should be added, however, Python gives this error: `TypeError: pluspress() missing 1 required positional argument: 'textinput'`. Here is the text of the program:
from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.textinput import TextInput
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.gridlayout import GridLayout
from kivy.uix.label import Label
from kivy.config import Config
Config.set('graphics', 'width', '800')
Config.set('graphics', 'height', '400')
Config.set('graphics', 'resizable', '0')
class ThoughtApp(App):
def build (self):
base=(BoxLayout(orientation='vertical'))
fl=FloatLayout()
adduser=(Label(text='Добавить участника:',
pos=(-120,360),
font_size=22,
bold=True,
font_name='C:\Windows\Fonts\calibril.ttf',
size_hint=(.6,.1)))
fl.add_widget(adduser)
textinput=(TextInput(multiline=False,
pos=(225,355),
size_hint=(.5,.15),
font_size=16))
fl.add_widget(textinput)
plusbtn=(Button(size_hint=(27/800,30/800),
text='+',
pos=(635,366.5),
on_press=self.pluspress,
background_color=[.55,.55,.55,1],
background_normal=''))
fl.add_widget(plusbtn)
base.add_widget(fl)
names_gl=GridLayout(rows=1,)
base.add_widget(names_gl)
return base
def pluspress(self,names_gl,textinput):
names_gl.add_widget(Button(text=textinput.text,
background_color=[.1,.9,.9,1],
background_normal=''))
textinput.text=''
if __name__ == '__main__':
ThoughtApp().run()
Answer the question
In order to leave comments, you need to log in
from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.textinput import TextInput
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.gridlayout import GridLayout
from kivy.uix.label import Label
from kivy.config import Config
Config.set('graphics', 'width', '800')
Config.set('graphics', 'height', '400')
Config.set('graphics', 'resizable', '0')
class ThoughtApp(App):
def build (self):
base=(BoxLayout(orientation='vertical'))
fl=FloatLayout()
adduser=(Label(text='Добавить участника:',
pos=(-120,360),
font_size=22,
bold=True,
font_name='C:\Windows\Fonts\calibril.ttf',
size_hint=(.6,.1)))
fl.add_widget(adduser)
self.textinput=(TextInput(multiline=False,
pos=(225,355),
size_hint=(.5,.15),
font_size=16))
fl.add_widget(self.textinput)
plusbtn=(Button(size_hint=(27/800,30/800),
text='+',
pos=(635,366.5),
on_press=self.pluspress,
background_color=[.55,.55,.55,1],
background_normal=''))
fl.add_widget(plusbtn)
base.add_widget(fl)
self.names_gl=GridLayout(rows=1,)
base.add_widget(self.names_gl)
return base
def pluspress(self, event):
self.names_gl.add_widget(Button(text=self.textinput.text,
background_color=[.1,.9,.9,1],
background_normal=''))
self.textinput.text=''
if __name__ == '__main__':
ThoughtApp().run()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question