我在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.destroy()替换为self.close()。