You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import kivy
from kivy.app import App
from kivy.uix.gridlayout import GridLayout
from kivy.uix.label import Label
from kivy.uix.textinput import TextInput
from kivy.uix.button import Button
#Set columns
self.cols = 2
#Add widgets
self.add_widget(Label(text='Name: '))
#Add Input Box
self.name = TextInput(multiline=False)
self.add_widget(self.name)
self.add_widget(Label(text='Favorite Pizza: '))
# Add Input Box
self.pizza = TextInput(multiline=False)
self.add_widget(self.pizza)
self.add_widget(Label(text='Favorite Color: '))
# Add Input Box
self.color = TextInput(multiline=False)
self.add_widget(self.color)
#Create Submit Button
self.submit = Button(text='Submit', font_size= 32)
#Bind the button
self.submit.bind(on_press=self.press)
self.add_widget(self.submit)
def press(self, instance):
name = self.name.text
pizza = self.pizza.text
color = self.color.text
#print(f'Hello {name}, you like {pizza} pizza, and your favorite color is {color}!')
#Print in to the screen
self.add_widget(Label(text=f'Hello {name}, you like {pizza} pizza, and your favorite color is {color}!'))
class MyApp(App):
def build(self):
return MyGridLayout()
if name == 'main':
MyApp().run()
But Visual Studios have error:
PS C:\Users\fesus> & C:/Python312/python.exe c:/Users/fesus/.vscode/input.py
[INFO ] [Logger ] Record log in C:\Users\fesus.kivy\logs\kivy_24-08-28_21.txt
[INFO ] [deps ] Successfully imported "kivy_deps.gstreamer" 0.3.3
[INFO ] [deps ] Successfully imported "kivy_deps.angle" 0.4.0
[INFO ] [deps ] Successfully imported "kivy_deps.glew" 0.3.1
[INFO ] [deps ] Successfully imported "kivy_deps.sdl2" 0.7.0
[INFO ] [Kivy ] v2.3.0
[INFO ] [Kivy ] Installed at "C:\Python312\Lib\site-packages\kivy_init_.py"
[INFO ] [Python ] v3.12.2 (tags/v3.12.2:6abddd9, Feb 6 2024, 21:26:36) [MSC v.1937 64 bit (AMD64)]
[INFO ] [Python ] Interpreter at "C:\Python312\python.exe"
[INFO ] [Logger ] Purge log fired. Processing...
[INFO ] [Logger ] Purge finished!
[INFO ] [Factory ] 195 symbols loaded
[INFO ] [Image ] Providers: img_tex, img_dds, img_sdl2 (img_pil, img_ffpyplayer ignored)
[INFO ] [Text ] Provider: sdl2
[INFO ] [Window ] Provider: sdl2
[INFO ] [GL ] Using the "OpenGL" graphics system
[INFO ] [GL ] GLEW initialization succeeded
[INFO ] [GL ] Backend used
[INFO ] [GL ] OpenGL version <b'4.6.0 - Build 31.0.101.4032'>
[INFO ] [GL ] OpenGL vendor <b'Intel'>
[INFO ] [GL ] OpenGL renderer <b'Intel(R) Iris(R) Xe Graphics'>
[INFO ] [GL ] OpenGL parsed version: 4, 6
[INFO ] [GL ] Shading version <b'4.60 - Build 31.0.101.4032'>
[INFO ] [GL ] Texture max size <16384>
[INFO ] [GL ] Texture max units <32>
[INFO ] [Window ] auto add sdl2 input provider
[INFO ] [Window ] virtual keyboard not allowed, single mode, not docked
[INFO ] [Base ] Start application main loop
[INFO ] [GL ] NPOT texture support is available
[INFO ] [Base ] Leaving application in progress...
Traceback (most recent call last):
File "c:\Users\fesus.vscode\input.py", line 44, in
MyApp().run()
File "C:\Python312\Lib\site-packages\kivy\app.py", line 956, in run
runTouchApp()
File "C:\Python312\Lib\site-packages\kivy\base.py", line 574, in runTouchApp
EventLoop.mainloop()
File "C:\Python312\Lib\site-packages\kivy\base.py", line 339, in mainloop
self.idle()
File "C:\Python312\Lib\site-packages\kivy\base.py", line 383, in idle
self.dispatch_input()
File "C:\Python312\Lib\site-packages\kivy\base.py", line 334, in dispatch_input
post_dispatch_input(*pop(0))
File "C:\Python312\Lib\site-packages\kivy\base.py", line 263, in post_dispatch_input
listener.dispatch('on_motion', etype, me)
File "kivy\_event.pyx", line 731, in kivy.event.EventDispatcher.dispatch
File "C:\Python312\Lib\site-packages\kivy\core\window_init.py", line 1709, in on_motion
self.dispatch('on_touch_down', me)
File "kivy\_event.pyx", line 731, in kivy.event.EventDispatcher.dispatch
File "C:\Python312\Lib\site-packages\kivy\core\window_init.py", line 1726, in on_touch_down
if w.dispatch('on_touch_down', touch):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "kivy\_event.pyx", line 731, in kivy._event.EventDispatcher.dispatch
File "C:\Python312\Lib\site-packages\kivy\uix\widget.py", line 589, in on_touch_down
if child.dispatch('on_touch_down', touch):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "kivy\_event.pyx", line 731, in kivy._event.EventDispatcher.dispatch
File "C:\Python312\Lib\site-packages\kivy\uix\behaviors\button.py", line 151, in on_touch_down
self.dispatch('on_press')
File "kivy\_event.pyx", line 727, in kivy._event.EventDispatcher.dispatch
File "kivy\_event.pyx", line 1307, in kivy._event.EventObservers.dispatch
File "kivy\_event.pyx", line 1231, in kivy._event.EventObservers._dispatch
TypeError: MyGridLayout.press() takes 1 positional argument but 2 were given
It is the code:
import kivy.app
from kivy.uix.button import Button
from kivy.uix.gridlayout import GridLayout
from kivy.uix.label import Label
from kivy.uix.textinput import TextInput
class MyGridLayout(GridLayout):
def init(self, **kwargs):
super(GridLayout, self).init(**kwargs)
self.cols = 2
self.add_widget(Label(text='Name: '))
self.name = TextInput(multiline=False)
self.add_widget(self.name)
self.add_widget(Label(text='Favorite Pizza: '))
self.pizza = TextInput(multiline=False)
self.add_widget(self.pizza)
self.add_widget(Label(text='Favorite Color: '))
self.color = TextInput(multiline=False)
self.add_widget(self.color)
self.submit = Button(text='Submit', font_size=32)
self.submit.bind(on_press=self.press)
self.add_widget(self.submit)
def press(self):
name = self.name.text
pizza = self.pizza.text
color = self.color.text
self.add_widget(Label(text=f'Hello {name}, you like {pizza} pizza, and your favorite color is {color}!'))
class MyApp(kivy.app.App):
def build(self):
return MyGridLayout()
if name == 'main':
MyApp().run()
I don't know what is wrong.
Anybody can help me?
Thanks!
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello!
I have a problem. In Pycharm I haven't got error cod, but my program isn't working.
I made a program based on a video.
https://www.youtube.com/watch?v=S41RPtdWe78&list=PLCC34OHNcOtpz7PJQ7Tv7hqFBP_xDDjqg&index=2
import kivy
from kivy.app import App
from kivy.uix.gridlayout import GridLayout
from kivy.uix.label import Label
from kivy.uix.textinput import TextInput
from kivy.uix.button import Button
class MyGridLayout(GridLayout):
#Initialize infinite keywords
def init(self, **kwargs):
#Call grid layout constructor
super(GridLayout, self).init(**kwargs)
class MyApp(App):
def build(self):
return MyGridLayout()
if name == 'main':
MyApp().run()
But Visual Studios have error:
PS C:\Users\fesus> & C:/Python312/python.exe c:/Users/fesus/.vscode/input.py
[INFO ] [Logger ] Record log in C:\Users\fesus.kivy\logs\kivy_24-08-28_21.txt
[INFO ] [deps ] Successfully imported "kivy_deps.gstreamer" 0.3.3
[INFO ] [deps ] Successfully imported "kivy_deps.angle" 0.4.0
[INFO ] [deps ] Successfully imported "kivy_deps.glew" 0.3.1
[INFO ] [deps ] Successfully imported "kivy_deps.sdl2" 0.7.0
[INFO ] [Kivy ] v2.3.0
[INFO ] [Kivy ] Installed at "C:\Python312\Lib\site-packages\kivy_init_.py"
[INFO ] [Python ] v3.12.2 (tags/v3.12.2:6abddd9, Feb 6 2024, 21:26:36) [MSC v.1937 64 bit (AMD64)]
[INFO ] [Python ] Interpreter at "C:\Python312\python.exe"
[INFO ] [Logger ] Purge log fired. Processing...
[INFO ] [Logger ] Purge finished!
[INFO ] [Factory ] 195 symbols loaded
[INFO ] [Image ] Providers: img_tex, img_dds, img_sdl2 (img_pil, img_ffpyplayer ignored)
[INFO ] [Text ] Provider: sdl2
[INFO ] [Window ] Provider: sdl2
[INFO ] [GL ] Using the "OpenGL" graphics system
[INFO ] [GL ] GLEW initialization succeeded
[INFO ] [GL ] Backend used
[INFO ] [GL ] OpenGL version <b'4.6.0 - Build 31.0.101.4032'>
[INFO ] [GL ] OpenGL vendor <b'Intel'>
[INFO ] [GL ] OpenGL renderer <b'Intel(R) Iris(R) Xe Graphics'>
[INFO ] [GL ] OpenGL parsed version: 4, 6
[INFO ] [GL ] Shading version <b'4.60 - Build 31.0.101.4032'>
[INFO ] [GL ] Texture max size <16384>
[INFO ] [GL ] Texture max units <32>
[INFO ] [Window ] auto add sdl2 input provider
[INFO ] [Window ] virtual keyboard not allowed, single mode, not docked
[INFO ] [Base ] Start application main loop
[INFO ] [GL ] NPOT texture support is available
[INFO ] [Base ] Leaving application in progress...
Traceback (most recent call last):
File "c:\Users\fesus.vscode\input.py", line 44, in
MyApp().run()
File "C:\Python312\Lib\site-packages\kivy\app.py", line 956, in run
runTouchApp()
File "C:\Python312\Lib\site-packages\kivy\base.py", line 574, in runTouchApp
EventLoop.mainloop()
File "C:\Python312\Lib\site-packages\kivy\base.py", line 339, in mainloop
self.idle()
File "C:\Python312\Lib\site-packages\kivy\base.py", line 383, in idle
self.dispatch_input()
File "C:\Python312\Lib\site-packages\kivy\base.py", line 334, in dispatch_input
post_dispatch_input(*pop(0))
File "C:\Python312\Lib\site-packages\kivy\base.py", line 263, in post_dispatch_input
listener.dispatch('on_motion', etype, me)
File "kivy\_event.pyx", line 731, in kivy.event.EventDispatcher.dispatch
File "C:\Python312\Lib\site-packages\kivy\core\window_init.py", line 1709, in on_motion
self.dispatch('on_touch_down', me)
File "kivy\_event.pyx", line 731, in kivy.event.EventDispatcher.dispatch
File "C:\Python312\Lib\site-packages\kivy\core\window_init.py", line 1726, in on_touch_down
if w.dispatch('on_touch_down', touch):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "kivy\_event.pyx", line 731, in kivy._event.EventDispatcher.dispatch
File "C:\Python312\Lib\site-packages\kivy\uix\widget.py", line 589, in on_touch_down
if child.dispatch('on_touch_down', touch):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "kivy\_event.pyx", line 731, in kivy._event.EventDispatcher.dispatch
File "C:\Python312\Lib\site-packages\kivy\uix\behaviors\button.py", line 151, in on_touch_down
self.dispatch('on_press')
File "kivy\_event.pyx", line 727, in kivy._event.EventDispatcher.dispatch
File "kivy\_event.pyx", line 1307, in kivy._event.EventObservers.dispatch
File "kivy\_event.pyx", line 1231, in kivy._event.EventObservers._dispatch
TypeError: MyGridLayout.press() takes 1 positional argument but 2 were given
It is the code:
import kivy.app
from kivy.uix.button import Button
from kivy.uix.gridlayout import GridLayout
from kivy.uix.label import Label
from kivy.uix.textinput import TextInput
class MyGridLayout(GridLayout):
def init(self, **kwargs):
super(GridLayout, self).init(**kwargs)
class MyApp(kivy.app.App):
def build(self):
return MyGridLayout()
if name == 'main':
MyApp().run()
I don't know what is wrong.
Anybody can help me?
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions