menuBar.addAction更改文本
问题描述:
我正在使用python QtGui。menuBar.addAction更改文本
当我想改变文本时,我得到错误。
Traceback (most recent call last):
File "main2.py", line 140, in ChangeLanguage
self.fileMenu2.setText("www")
AttributeError: 'QMenu' object has no attribute 'setText'
这里是我的代码:
from PyQt4 import QtCore,QtGui,QMainWindow
...
class MainWindow(QtGui.QMainWindow):
def __init__(self,parent=None):
super(MainWindow,self).__init__(parent)
menubar = self.menuBar()
self.fileMenu = menubar.addMenu('test')
...
def ChangeLanguage(self):
self.fileMenu.setText("test2")
我应该如何改变文本?
感谢
编辑:对不起,这是QtGui.QMainWindow ......没有Tkinter的
答
的QMenu
类没有setText
方法类似QAction
一样。您需要使用setTitle
代替:
self.fileMenu.setTitle("test2")
+0
它改变了!谢谢! – eason
这看起来不像tkinter代码。 'QMenu'看起来像一个qt小部件。 –
哦,我错了。对不起,我会编辑它。 – eason