1

我需要复制文本以备后用在按(ctrl + c)时,会有错误所以我使用了气泡,但出现了同样的错误

*****Python********

from kivy.app import App
from kivy.uix.popup import Popup
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.lang import Builder

class Progress(Popup):
    pass
class ScreenManagement(ScreenManager):
    pass

class Func(Screen):
    pass

presentation = Builder.load_file("try_.kv")

class MainApp(App):
    Progress = Progress()
    def build(self):
        return presentation
if __name__ == "__main__":
    MainApp().run()

*****KV 文件********

#:import Factory kivy.factory.Factory
# #:import Clipboard kivy.core.clipboard.Clipboard
<Progress>:
    text: ""
    separator_color: 0, 0, 0, 0

    BoxLayout:
        TextInput:
            id: textinput
            text: "Your Key is samphone"
            copydata: 'text'
            readonly: True
            use_bubble: True
            allow_copy: True

        Button:
            text: "Click"
            on_release:
                root.dismiss()

ScreenManagement:
    Func:

<Func>:
    BoxLayout:
        Button:
            text: "Click"
            on_release:
                Factory.Progress().open()

****错误*****

文件“C:\Users\Sherif\AppData\Local\Programs\Python\Python35\lib\site-packages\kivy\uix\textinput.py”,第 378 行,在做 textinput.copy() 文件“C:\Users \Sherif\AppData\Local\Programs\Python\Python35\lib\site-packages\kivy\uix\textinput.py”,第 1712 行,在副本中返回 Clipboard.copy(self.selection_text) 文件“C:\Users\Sherif \AppData\Local\Programs\Python\Python35\lib\site-packages\kivy\core\clipboard__init__.py”,第 73 行,复制 self._copy(data) 文件“C:\Users\Sherif\AppData\Local\ Programs\Python\Python35\lib\site-packages\kivy\core\clipboard__init__.py",第 87 行,在 _copy self.put(data, self._clip_mime_type)

文件“C:\Users\Sherif\AppData\Local\Programs\Python\Python35\lib\site-packages\kivy\core\clipboard\clipboard_winctypes.py”,第 55 行,放入 msvcrt.wcscpy_s(c_wchar_p(hCd), len(文本),c_wchar_p(文本))

ValueError:嵌入的空字符

4

2 回答 2

0

实际上,ValueError这里的全部内容“仅”是关于此拉取请求中 CPython 内部的最近( 3.5.4+ 和+)更改,这基本上对于我们的 ctypes 剪贴板意味着调用更改的 API而不是原始API,并且如提交消息中所述3.6.3_PyUnicode_AsUnicodePyUnicode_AsUnicode

_PyUnicode_AsUnicode() 类似于 PyUnicode_AsUnicode(),但检查空字符。

它引发了一个错误。解决这个问题需要一段时间,因为我没有在发行说明中找到它,但是它已在kivy#5579中修复,并且很快会在 master 分支中。

于 2018-01-18T22:23:41.153 回答
0

有关详细信息,请参阅以下示例:

例子

主文件

from kivy.app import App
from kivy.uix.popup import Popup
from kivy.uix.screenmanager import ScreenManager, Screen


class Progress(Popup):
    pass


class Func(Screen):
    pass


class ScreenManagement(ScreenManager):
    pass


class MainApp(App):

    def build(self):
        return ScreenManagement()


if __name__ == "__main__":
    MainApp().run()

主文件

#:import Factory kivy.factory.Factory

<Progress>:
    text: ""
    separator_color: 0, 0, 0, 0

    BoxLayout:
        TextInput:
            id: textinput
            text: "Your Key is samphone"
            readonly: True
            allow_copy: True
            copydata: self.text

        Button:
            text: "Click"
            on_release:
                root.dismiss()

<Func>:
    BoxLayout:
        Button:
            text: "Click"
            on_release:
                Factory.Progress().open()

<ScreenManagement>:
    Func:

输出 - 稍后粘贴

在此处输入图像描述

于 2017-09-05T22:26:23.270 回答