如何解决PyGtk:我不能使用vte库函数吗?
我正在尝试将命令发送到Vte终端,但我一直收到相同的错误。另外,我在互联网上找不到其他工作示例。由于目前我的代码尚不完整,因此向您展示了stackoverflow中的示例。它给出了相同的错误。
错误消息:
File "~/basic-terminal/terminal.py",line 52,in InputToTerm
self.terminal.feed_child(self.command,length)
TypeError: Vte.Terminal.feed_child() takes exactly 2 arguments (3 given)
代码:
from gi.repository import Gtk,GObject,Vte
#GObject is not required. I just import it everywhere just in case.
#Gtk,Vte,and GLib are required.
from gi.repository import GLib
import os
#os.environ['HOME'] helps to keep from hard coding the home string.
#os is not required unless you want that functionality.
class TheWindow(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self,title="inherited cell renderer")
self.set_default_size(600,300)
self.terminal = Vte.Terminal()
self.terminal.fork_command_full(
Vte.PtyFlags.DEFAULT,#default is fine
os.environ['HOME'],#where to start the command?
["/bin/sh"],#where is the emulator?
[],#it's ok to leave this list empty
GLib.SpawnFlags.DO_NOT_REAP_CHILD,None,#at least None is required
None,)
#Set up a button to click and run a demo command
self.button = Gtk.Button("Do The Command")
#To get the command to automatically run
#a newline(\n) character is used at the end of the
#command string.
self.command = "echo \"Sending this command to a virtual terminal.\"\n"
command = Gtk.Label("The command: "+self.command)
self.button.connect("clicked",self.InputToTerm)
#end demo command code
#set up the interface
box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
box.pack_start(self.button,False,True,0)
box.pack_start(command,1)
#a scroll window is required for the terminal
scroller = Gtk.ScrolledWindow()
scroller.set_hexpand(True)
scroller.set_vexpand(True)
scroller.add(self.terminal)
box.pack_start(scroller,2)
self.add(box)
def InputToTerm(self,clicker):
#get the command when the button is clicked
length = len(self.command)
#A length is not required but is the easiest mechanism.
#Otherwise the command must be null terminated.
#Feed the command to the terminal.
self.terminal.feed_child(self.command,length)
win = TheWindow()
win.connect("delete-event",Gtk.main_quit)
win.show_all()
Gtk.main()
我该怎么办?为什么我总是不断收到此错误?
解决方法
解决了问题。命令已更改。您也可以通过这种方式解决您的问题:)
self.terminal.feed_child(self.command.encode("utf-8"))
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。