我的python脚本关闭触摸板和电源按钮为什么?

2024-04-27 21:22:37 发布

您现在位置:Python中文网/ 问答频道 /正文

我在Manjaro linux上使用KDE。我有一个python脚本来关闭touchpad:

#!/usr/bin/python
import sys

from PyQt5.QtWidgets import QWidget, QPushButton, QApplication
from PyQt5.QtCore import QCoreApplication
from subprocess import call

class Example(QWidget):

def __init__(self):
    super().__init__()

    self.initUI()


def initUI(self):               

    qbtn = QPushButton('On', self)
    qbtn.clicked.connect(self.handleButtonOn)
    qbtn.resize(qbtn.sizeHint())
    qbtn.move(25, 50)  

    qbtn = QPushButton('Off', self)
    qbtn.clicked.connect(self.handleButtonOff)
    qbtn.resize(qbtn.sizeHint())
    qbtn.move(125, 50) 

    self.setGeometry(300, 300, 250, 100)
    self.setWindowTitle('Touchpad On/Off')    
    self.show()

def handleButtonOn(self, event):
    print ('On')
    call(["synclient", "touchpadoff=0"])
    call(["notify-send", "Your touchpad is set to ON"])
    self.destroy()

def handleButtonOff(self, event):
    print ('Off')
    call(["synclient", "touchpadoff=1"])
    call(["notify-send", "Your touchpad is set to OFF"])
    self.destroy()

if __name__ == '__main__':

app = QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_()) 

它的工作几乎是完美的(关闭我的触摸板),但当我启动脚本时,它关闭了我的电源按钮,所以我不能通过这个按钮关闭计算机。 Yakuake也有问题,不能在这个终端上写。最后,我启动了其他终端,例如“konsole”,并通过关闭命令关闭计算机。 我是python新手。如何让这个工作正常。我需要关闭我的触摸板,我使用外部鼠标。在


Tags: fromimportself脚本ondefsyscall
1条回答
网友
1楼 · 发布于 2024-04-27 21:22:37

我不能用电源按钮重现你的问题,但我发现了自我毁灭()导致您的脚本冻结在某个已损坏但未响应SIGINT状态。替换自我毁灭()与自动关闭()使它在我的机器上工作。在

请尝试更换自我毁灭()与自动关闭(). 在

相关问题 更多 >