使 xterm 窗口打开,直到用户将其关闭
如何调用一个永久的xterm窗口并且仅当用户关闭它时它才关闭?
这是将重现此问题的代码
import os
from PyQt4 import QtCore, QtGui
from main import Ui_MainWindow
class Main(QtGui.QMainWindow):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
QtCore.QObject.connect(self.ui.pushID, QtCore.SIGNAL('clicked()'), self.showid)
def showid(self):
process = subprocess.Popen(['lsusb'], shell=False, stdout=subprocess.PIPE)
process.communicate()[0]
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
main = Main()
main.show()
sys.exit(app.exec_())
有什么建议吗?
how to call a permanent xterm window and it's closed only when user close it?
here's the code that will recreate this problem
import os
from PyQt4 import QtCore, QtGui
from main import Ui_MainWindow
class Main(QtGui.QMainWindow):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
QtCore.QObject.connect(self.ui.pushID, QtCore.SIGNAL('clicked()'), self.showid)
def showid(self):
process = subprocess.Popen(['lsusb'], shell=False, stdout=subprocess.PIPE)
process.communicate()[0]
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
main = Main()
main.show()
sys.exit(app.exec_())
any suggestion?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不要使用
os.system
。使用 subprocess尽管您最好从
subprocess
获取输出,但无需涉及 xterm。请注意
shell=False
。这是读取 lsusb 命令输出的方式。如果您正在寻找有关
subprocess
的教程,此< /a> 很好。Don't use
os.system
. Use subprocessThough you are better getting the output from
subprocess
without involvingxterm
.Note that
shell=False
. This is how you would read the output from thelsusb
command.If you are looking for a tutorial on
subprocess
, this is good.这是一个老问题,但在这种情况下OP想要的是:
-hold(执行后保持xterm窗口打开)
-title(xterm 窗口中的名称) 如果没有 -title,窗口将采用执行的命令的名称,在本例中为
lsusb
-几何(终端宽度、高度、水平位置、垂直位置)
-e(此后的所有内容都是要运行的命令)
lsusb(我希望在 xterm 中运行的命令)
It's an old question but what the OP wanted in this case was:
-hold (keep the xterm window open once it has executed)
-title (the name in the xterm window) without -title the window takes the name of the command executed, in this case
lsusb
-geometry (terminal width, height,horizontal position, vertical position)
-e (everything after this is the command to run)
lsusb (the command I wish to run in xterm)