I need some help. I'm studying kivy and I use pycharm as IDE for development. To work with kivy I created a virtualenvs with requeriments:
kivy = 1.10
Cython = 0.23
Python = 3.5
As for setup I did not have too much trouble. It came later when I tried to generate a layout and it did not appear. Is my code:
# coding = utf-8
from kivy.app import App
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.textinput import TextInput
from kivy.uix.button import Button
from kivy.core.window import Window
def click():
print (ed.text)
def build():
layout = FloatLayout()
ed = TextInput(text="USER.COM")
global ed
ed.size_hint = None, None
ed.height = 300
ed.width = 400
ed.y = 60
ed.x = 250
bt = Button(text="Click Me")
bt.size_hint = None, None
bt.height = 50
bt.width = 200
bt.y = 150
bt.x = 170
bt.size_hint = None, None
bt.on_press = click()
layout.add_widget(ed)
layout.add_widget(bt)
return layout
Window.size=600,600
open= App()
open.title = "USER_FREE_AS"
open.buid=build
open.run()
The log reports that pycharm is not allowed to access the function. Is my log:
/home/user/.virtualenvs/k35/bin/python /home/user/Projetos/Python/kivy/source/tela_layout/main.py
/home/user/Projetos/Python/kivy/source/tela_layout/main.py:18: SyntaxWarning: name 'ed' is assigned to before global declaration
global ed
[INFO ] [Logger ] Record log in /home/victorpenna/.kivy/logs/kivy_17-11-13_11.txt
[INFO ] [Kivy ] v1.10.0
[INFO ] [Python ] v3.5.2 (default, Sep 14 2017, 22:51:06)
[GCC 5.4.0 20160609]
[INFO ] [Factory ] 194 symbols loaded
[INFO ] [Image ] Providers: img_tex, img_dds, img_sdl2, img_gif (img_pil, img_ffpyplayer ignored)
[INFO ] [Text ] Provider: sdl2
[INFO ] [OSC ] using <multiprocessing> for socket
[INFO ] [Window ] Provider: sdl2(['window_egl_rpi'] ignored)
[INFO ] [GL ] Using the "OpenGL" graphics system
[INFO ] [GL ] Backend used <gl>
[INFO ] [GL ] OpenGL version <b'3.0 Mesa 17.3.0-rc2 - padoka PPA'>
[INFO ] [GL ] OpenGL vendor <b'Intel Open Source Technology Center'>
[INFO ] [GL ] OpenGL renderer <b'Mesa DRI Intel(R) HD Graphics 5500 (Broadwell GT2) '>
[INFO ] [GL ] OpenGL parsed version: 3, 0
[INFO ] [GL ] Shading version <b'1.30'>
[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 ] [ProbeSysfs ] device match: /dev/input/event8
[INFO ] [MTD ] Read event from </dev/input/event8>
[INFO ] [ProbeSysfs ] device match: /dev/input/event13
[INFO ] [MTD ] Read event from </dev/input/event13>
[INFO ] [ProbeSysfs ] device match: /dev/input/event14
[INFO ] [MTD ] Read event from </dev/input/event14>
[INFO ] [Base ] Start application main loop
[WARNING] [MTD ] Unable to open device "/dev/input/event8". Please ensure you have the appropriate permissions.
[WARNING] [MTD ] Unable to open device "/dev/input/event13". Please ensure you have the appropriate permissions.
[WARNING] [MTD ] Unable to open device "/dev/input/event14". Please ensure you have the appropriate permissions.
[INFO ] [Base ] Leaving application in progress...
Process finished with exit code 0
How can I solve this problem?
P.S: My linux is ubuntu 16.04, Intel GPU.
You have a typo:
open.buid=build
should probably be
open.build=build
But don't do that. Putting methods to an instance afterwards (monkeypatching) gets very confusing fast. Other developers will not expect it in this situation. Also kivy does some magic with the classname of the app, it will locate the .kv
file following a naming convention. So instead write:
from kivy.app import App
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.textinput import TextInput
from kivy.uix.button import Button
from kivy.core.window import Window
class MyApp(App):
def click(self):
print(self.ed.text)
def build(self):
layout = FloatLayout()
self.ed = TextInput(text="USER.COM")
ed.size_hint = None, None
ed.height = 300
ed.width = 400
ed.y = 60
ed.x = 250
bt = Button(text="Click Me")
bt.size_hint = None, None
bt.height = 50
bt.width = 200
bt.y = 150
bt.x = 170
bt.size_hint = None, None
bt.on_press = click()
layout.add_widget(ed)
layout.add_widget(bt)
return layout
Window.size=600,600
open= MyApp()
open.title = "USER_FREE_AS"
open.run()
That way you also avoid the global variable, which is most of the time a sign that you do something suboptimal.
If you are still new to kivy I recommend going through the kivy tutorials.