gpt4 book ai didi

python - 从 PyQt 中的 QPushButton 获取文本

转载 作者:太空宇宙 更新时间:2023-11-03 13:04:25 25 4
gpt4 key购买 nike

<分区>

我正在尝试从 QtGui.QPushButton 对象列表创建一个简单的键盘。

class XKeyboard(QtGui.QWidget):
'''Special virtual keyboard for any language.'''
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.MainLayout = QtGui.QVBoxLayout()
self.TextEntry = QtGui.QTextEdit()
self.Keyboard = QtGui.QVBoxLayout()
self.MainLayout.addWidget(self.TextEntry)
self.MainLayout.addLayout(self.Keyboard)
self.setLayout(self.MainLayout)

def addRow(self, keys):
layout = QtGui.QHBoxLayout()
buttons = [QtGui.QPushButton(unicode(key)) for key in keys]
for button in buttons:
key = keys[buttons.index(button)]
layout.addWidget(button)
button.clicked.connect(
lambda key: self.keyClick(key))
self.keyClick(key)
self.Keyboard.addLayout(layout)

def keyClick(self, key):
self.TextEntry.insertPlainText(key)

问题是 lambda 返回 False 而不是 key。我做错了什么?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com