---
title: "(Get Maya Main Window for PyQt4/PySide)为PyQt4/PySide获取Maya的主窗口"
author: "schi"
date: "2012-07-02T22:47:45Z"
tags: ["Python", "Qt", "maya"]
categories: ["编程语言"]
slug: "get-maya-main-window-for-pyqt4-pyside-pyqt4-pyside-maya"
draft: false
lastmod: "2012-07-02T22:47:45Z"
id: 1575015
url: "https://schi.iteye.com/blog/1575015"
---

我们都知道Maya的主窗口保存在mel的全局变量**<span style="color:red">$gMainWindow</span>**里。
We all know that wen can get the main Maya window with **<span style="color:red">$gMainWindow</span>**.

```mel
print $gMainWindow;
//MayaWindow
```


因为Maya2011 和 Maya2012是使用Qt编写的界面，所以我们可十分轻松的获取Maya的主窗口。
Because the UI of Maya2011 and Maya2012 was based on Qt, os we can super easy to get the main window.

```python
#from PyQt4 import QtGui
from PySide import QtGui

for widget in QtGui.qApp.allWidgets():
    print widget.objectName()
```


> ......
> qt_scrollarea_viewport
> selectedDispLayer
> 
> ShadedBtn
> iconTextCheckBox4
> formLayout20
> tabLayout2
> 
> MayaWindow
> qt_dockwidget_floatbutton
> HotboxEast2
> formLayout5
> 
> 
> popupMenu48
> selectButton3
> 
> objPickMenuIcon
> ......