[英]My python script turn off touchpad and power button why?
我在Manjaro linux上使用KDE。 我在python中有这个脚本来关闭触摸板:
#!/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”,并通过shutdown命令关闭计算机。 我是python的新手。 如何使这项工作好。 我需要关掉我的触控板,我使用外接鼠标。
我无法使用电源按钮重现您的问题,但我发现self.destroy()导致您的脚本冻结在某些损坏 - 不响应 - SIGINT状态。 用self.close()替换self.destroy()使它在我的机器上运行。
请尝试用self.close()替换self.destroy()。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.