pythonpyqt4qmenubar

menuBar.addAction change the text


I'm using python QtGui.

When I want to change the text, I got error.

Traceback (most recent call last):
File "main2.py", line 140, in ChangeLanguage
self.fileMenu2.setText("www")
AttributeError: 'QMenu' object has no attribute 'setText'

Here is my Code:

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")

How should I change the text ?

THanks

edit: Sorry , It's QtGui.QMainWindow ... not Tkinter


Solution

  • The QMenu class doesn't have a setText method like QAction does. You need to use setTitle instead:

        self.fileMenu.setTitle("test2")