【发布时间】:2018-04-26 13:19:53
【问题描述】:
我需要一些帮助。我正在学习kivy,我使用pycharm作为IDE进行开发。 为了使用 kivy,我创建了一个带有要求的 virtualenvs:
kivy = 1.10
Cython = 0.23
Python = 3.5
至于设置,我没有太多麻烦。后来当我尝试生成布局时它出现了,但它没有出现。 是我的代码:
# 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()
日志报告不允许pycharm访问该函数。是我的日志:
/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
我该如何解决这个问题?
P.S:我的 linux 是 ubuntu 16.04,Intel GPU。
【问题讨论】:
-
问题不在于权限,而是您在未声明的情况下使用了变量:SyntaxWarning: name 'ed' is assigned to before global declaration global ed。解决方案是
global ed ed=TextInput(text="USER.COM") -
错误依旧,无法调用layout独立命令插入全局编辑
-
你试过从终端运行它吗?
-
错误仍然继续,即使是终端!
-
所以问题不在于 PyCharm,而在于 kivy。