【问题标题】:unable to call a function in python with pointer parameter无法在python中使用指针参数调用函数
【发布时间】:2021-03-08 06:28:19
【问题描述】:
class X:
    def initUI(self):
        self.setWindowTitle(self.title)
        self.setGeometry(self.left, self.top, self.width, self.height)
        ###########
        combo = QComboBox(self)
        shotcut_list = [
            "Key.f9",
            "Key.f2",
            "Key.f3",
            "Key.f4",
            "Key.f5",
            "Key.f6",
            "Key.f7",
            "Key.f8",
            "Key.f1",
            "Key.f10",
            "Key.f11",
            "Key.f12",
        ]
        combo.addItems(shotcut_list)
        global shortcut
        global cptext
        shortcut = combo.currentText()
        combo.setGeometry(350, 120, 120, 30)
        combo.activated[str].connect(self.onChanged)
        # Create textbox
        self.textbox = QPlainTextEdit(self)
        self.textbox.move(20, 160)
        self.textbox.setReadOnly(True)
        self.textbox.resize(500, 205)
        self.setGeometry(70, 70, 540, 388)
        self.show()

    def onChanged(self, text):
        global shortcut
        shortcut = text

    def update(self):
        self.textbox.insertPlainText(cptext)
        print(cptext)

    def print_key(*self):
        print(self[0])
        if str(self[1]) == shortcut:
            global cptext
            cptext = pc.paste()
            keyboard.type(cptext)
            self.textbox.insertPlainText(
                cptext
            )  # cannot call the text box using self

【问题讨论】:

  • 是因为Python没有指针吗?

标签: python pyqt5


【解决方案1】:

是的,*self 不是 Python 中的“指针参数”,它是可变数量参数的元组解包。试试

    def print_key(self, key):
        print(self)
        if str(key) == shortcut:
             # ...

相反(或者如果print_key 被发送更多你不关心的参数,print_key(self, key, *args))...

【讨论】:

  • def print_key(*self): print(self[0]) if str(self[1]) == shortcut: global cptext cptext = pc.paste() keyboard.type(cptext) self .textbox.insertPlainText(cptext) def key(self): listener = Listener(on_press=self.print_key) listener.start()
  • @AshfaqueKhan 我不知道该评论什么。
  • 非常感谢,我在这个巨大的帮助下开始了新的工作
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-01-04
  • 1970-01-01
  • 2016-11-14
  • 1970-01-01
  • 1970-01-01
  • 2011-04-20
  • 1970-01-01
相关资源
最近更新 更多