ubuntu 无法访问该页面?

plicqrtu  于 2023-05-28  发布在  其他
关注(0)|答案(3)|浏览(161)

我需要帮助我正在学习kivy,我使用pycharm作为开发的IDE。为了与kivy一起工作,我创建了一个virtualenvs,其中包含requeriments:

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。

rqcrx0a6

rqcrx0a61#

暗窗

由于存在打字错误,显示了一个黑色窗口。
替换:

open.buid=build

其中:

open.build=build

Kivy文档

Programming Guide » Kivy Basics
Programming Guide » Kv language

设备权限

要使用这些设备,您需要授予用户或组权限。这可以通过以下方式完成(在您的情况下,将“X”替换为8,13,14):

$ sudo chmod u+r /dev/input/eventX

SyntaxWarning:名称'艾德'

在赋值之前,应该声明全局变量***艾德***。

ed = ""

def click():
    print (ed.text)

def build():
    global ed

    layout = FloatLayout()

    ed = TextInput(text="USER.COM")

输出

llycmphe

llycmphe2#

event<X>的所有者更改为当前用户
sudo chown $whoami:input /dev/input/event8
或以root身份运行它,如
sudo ./env/bin/python3 main.py

q8l4jmvw

q8l4jmvw3#

您有一个错字:

open.buid=build

应该是

open.build=build

但别这么做之后将方法放到示例中(monkeypatching)会很快变得非常混乱。其他开发人员在这种情况下不会想到它。kivy还对应用程序的类名做了一些魔术,它将按照命名约定定位.kv文件。因此,改为写:

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()

这样你也避免了全局变量,这是大多数时候你做的事情不太理想的标志。
如果你还是kivy的新手,我建议你通过kivy tutorials

相关问题