Gtk 我不能使用vte库函数?

Gtk 我不能使用vte库函数?,gtk,pygtk,vte,Gtk,Pygtk,Vte,我正试图向Vte终端发送命令,但不断收到相同的错误。此外,我在互联网上找不到任何其他有效的例子。由于我的代码目前还不完整,我将向您展示一个来自的示例。它给出了同样的错误 错误消息: File "~/basic-terminal/terminal.py", line 52, in InputToTerm self.terminal.feed_child(self.command, length) TypeError: Vte.Terminal.feed_child()

我正试图向Vte终端发送命令,但不断收到相同的错误。此外,我在互联网上找不到任何其他有效的例子。由于我的代码目前还不完整,我将向您展示一个来自的示例。它给出了同样的错误

错误消息:

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, False, True, 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, False, True, 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()

我能做什么?为什么我经常会遇到这个错误?

解决了这个问题。命令已更改。您也可以通过以下方式解决问题:)


也许是因为这一个正好需要2个参数(给出3个)?是的,这就是问题所在。我只给出了两个参数。你能再检查一遍你的代码,确保你已经把给出错误的那一行复制到问题中了吗?因为从目前的情况看,不可能分辨出什么是错的。您的代码清楚地显示只有两个参数被传递到
feed\u child
,但错误消息同样清楚地显示系统认为有三个参数。是的,您是对的。很抱歉没有在这里写代码。我改变了问题。你能再看看吗?
self.terminal.feed_child(self.command.encode("utf-8"))