Kivy 使用触摸屏调用两次功能,但使用鼠标则不行

问题描述 投票:0回答:2

我正在一个学校项目中,在 Rasp pi 4 Model B 上使用 kivy。

当我使用鼠标(使用 vnc)时,函数 get 调用一次,但当我使用触摸屏时,函数 get 调用两次。

我已经尝试对我的 kivy config.ini 进行一些修改,但没有任何效果。

我的Python代码:

class WindowAdminConfigLockerESPAdd(Screen):
    global deviceLocalName
    number = ''

    def on_enter(self):
        self.ids.TxtAdminConfigLockerESP.text= 'Ajouter des casiers à l ' + deviceLocalName
        pass

    def clearTxt(self):
        self.ids.TxtPin.text=''
        pass

    def PressedButton(self,button):
        print("Appel fonction")
        self.ids.TxtPin.text = self.ids.TxtPin.text + str(button)
        self.number = self.number + str(button) 
        pass

    def Validate(self):
        if(nlc.addNumberLockersConfig(deviceLocalName,self.number)):
            nlc.saveNumberLockersConfigFile()
        self.clearTxt()
    pass

class FenetreManager(ScreenManager):
    pass

kv = Builder.load_file("monkv.kv")

class MonApplicationPrincipale(App):
    def build(self):
        Window.clearcolor = (223/255,223/255,223/255,1)
        return kv

    

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

我的.kv部分

<WindowAdminConfigLockerESPAdd>:

    name: "adminConfigLockerESPAdd"
    BoxLayout:
        canvas :
            Rectangle:
                source:'helmo.jfif'
                size: self.size
                pos: self.pos 
        orientation: "vertical"
        spacing:
            20
        padding:
            20
        size:
            root.width, root.height
        Label:
            id : TxtAdminConfigLockerESP
            halign : "center"
            text:""
        BoxLayout:
            orientation: "horizontal"
            spacing:
                20
            padding:
                20
        TextInput:
            id: TxtPin
            text:""
            halign:"right"
            font_size:35
            size_hint:(1,1)
        GridLayout:
            cols:3
            rows:4
            size_hint:(1,4)
            spacing : 2
            Button:
                size_hint:(.33,.25)
                font_size:32
                text:"1"
                on_press:root.PressedButton(1)
            
            Button:
                size_hint:(.33,.25)
                font_size:32
                text:"2"
                on_press:root.PressedButton(2)
            
            Button:
                size_hint:(.33,.25)
                font_size:32
                text:"3"
                on_press:root.PressedButton(3)

            Button:
                size_hint:(.33,.25)
                font_size:32
                text:"4"
                on_press:root.PressedButton(4)
            
            Button:
                size_hint:(.33,.25)
                font_size:32
                text:"5"
                on_press:root.PressedButton(5)
            
            Button:
                size_hint:(.33,.25)
                font_size:32
                text:"6"
                on_press:root.PressedButton(6)
            
            Button:
                size_hint:(.33,.25)
                font_size:32
                text:"7"
                on_press:root.PressedButton(7)
            
            Button:
                size_hint:(.33,.25)
                font_size:32
                text:"8"
                on_press:root.PressedButton(8)
            
            Button:
                size_hint:(.33,.25)
                font_size:32
                text:"9"
                on_press:root.PressedButton(9)

            Button:
                size_hint:(.33,.25)
                font_size:32
                text:""
            
            Button:
                size_hint:(.33,.25)
                font_size:32
                text:"0"
                on_press:root.PressedButton(0)
            
            Button:
                id: clearTxtPin
                size_hint:(.33,.25)
                font_size:32
                text:"C"
                background_color : (104/255,104/255,104/255,1)
                on_press : root.clearTxt()
        RoundedButton:
            id : BtnValidatePin
            text:"Valider"
            on_release:
                root.Validate()
                root.manager.transition.direction = "left"
            pos_hint:
                {'center_x':0.5}
            size_hint:
                (0.9,0.9)

        RoundedButton:
            text:"Retour"
            pos_hint:
                {'center_x':0.5}
            size_hint:
                (0.9,0.9)
            on_release:
                #root.clear()
                app.root.current = "adminChoice"
                root.manager.transition.direction = "right"

我的kivy config.ini

[kivy]
keyboard_repeat_delay = 300
keyboard_repeat_rate = 30
log_dir = logs
log_enable = 1
log_level = info
log_name = kivy_%y-%m-%d_%_.txt
window_icon = 
keyboard_mode = 
keyboard_layout = qwerty
desktop = 1
exit_on_escape = 1
pause_on_minimize = 0
kivy_clock = default
default_font = ['Roboto', 'data/fonts/Roboto-Regular.ttf', 'data/fonts/Roboto-Italic.ttf', 'data/fonts/Roboto-Bold.ttf', 'data/fonts/Roboto-BoldItalic.ttf']
log_maxfiles = 100
window_shape = data/images/defaultshape.png
config_version = 24

[graphics]
display = -1
fullscreen = 0
height = 600
left = 0
maxfps = 60
multisamples = 2
position = auto
rotation = 0
show_cursor = 1
top = 0
width = 800
resizable = 1
borderless = 0
window_state = visible
minimum_width = 0
minimum_height = 0
min_state_time = .035
allow_screensaver = 1
shaped = 0
vsync = 
verify_gl_main_thread = 1
custom_titlebar = 0
custom_titlebar_border = 5
always_on_top = 0
show_taskbar_icon = 1

[input]
mouse = mouse
%(name)s = probesysfs

[postproc]
double_tap_distance = 20
double_tap_time = 250
ignore = []
jitter_distance = 0
jitter_ignore_devices = mouse,mactouch,
retain_distance = 50
retain_time = 0
triple_tap_distance = 20
triple_tap_time = 375

[widgets]
scroll_timeout = 250
scroll_distance = 20
scroll_friction = 1.
scroll_stoptime = 300
scroll_moves = 5

[modules]

[network]
useragent = curl
implementation = default

该函数只需调用一次,因为如果您尝试输入“67”,则输入“6677”。

如果有人知道的话

谢谢,

python function kivy kivy-language touchscreen
2个回答
0
投票

我并没有真正找到解决方案,我只是进入了ubuntu桌面。但如果有人找到想法或解决方案,我想要它。


0
投票

我的问题是 KIVY 配置中的这一行。

鼠标=鼠标

当我使用 sudo python3 而不是 python3 来执行代码时,KIVY 配置使用的是 admin 配置而不是 usr 配置。

因此,使用该命令,我更改了管理 KIVY 配置

sudo su
cd /root/.kivy
nano config.ini
© www.soinside.com 2019 - 2024. All rights reserved.